我自己找到了很棒的解决方案。诀窍是在表格视图数据源 NSArray 中创建带有圆角的图像。我做了这样的方向:
1.1 将 QuartzCore 框架添加到项目中。
1.2 然后为 UIImage 添加类别。UIImage+圆角.h:
#import <UIKit/UIKit.h>
@interface UIImage (RoundedCorners)
- (UIImage *)imageWithRoundedCorners:(CGFloat)radius;
@end
1.3 UIImage+圆角.m:
#import "UIImage+RoundedCorners.h"
#import <QuartzCore/QuartzCore.h>
@implementation UIImage (RoundedCorners)
- (UIImage *)imageWithRoundedCorners:(CGFloat)radius;
{
CALayer *imageLayer = [CALayer layer];
imageLayer.frame = CGRectMake(0, 0, self.size.width, self.size.height);
imageLayer.contents = (id)self.CGImage;
imageLayer.masksToBounds = YES;
imageLayer.cornerRadius = radius;
UIGraphicsBeginImageContext(self.size);
[imageLayer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *roundedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return roundedImage;
}
@end
2.1 使用要使用的图像创建 NSArray (NSMutableArray):
_thumbnailImages = [[NSMutableArray alloc] initWithCapacity:[_dishes count]];
for (int counter = 0; counter < [_dishes count]; counter++)
{
EBEntityDish *dish = [_dishes objectAtIndex:counter];
[_thumbnailImages addObject:[dish.image.thumbnailImage imageWithRoundedCorners:IMAGE_CORNER_RADIUS]];
}
2.2 注意事项:
IMAGE_CORNER_RADIUS == your image corner radius.
_dishes - My objects that contain images small size (144 x 144)
2.3 结果:
My FPS increased on 10 - 20 FPS! Really awesome! Good luck!