- 設(shè)置圓角
-(UIImage *)avaterImageWithImage:(UIImage *)image size:(CGSize)size backColor:(UIColor *)backColor{
CGRect rect = CGRectMake(0, 0, size.width, size.height);
UIGraphicsBeginImageContextWithOptions(size, true, 0);
//0.背景填充
[backColor setFill];
UIRectFill(rect);
//1.實例化圓形路徑
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:rect];
[path addClip];
//2.在指定區(qū)域拉伸屏幕
[image drawInRect:rect];
//3.繪制內(nèi)切的圓形
[[UIColor darkGrayColor] setStroke];
path.lineWidth = 2;
[path stroke];
//4.獲取image
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
//5.關(guān)閉上下文
UIGraphicsEndImageContext();
return result;
}
- 柵格化
缺點耗電會增加
//異步繪制
self.layer.drawsAsynchronously = YES;
//柵格化
self.layer.shouldRasterize = YES;
//指定分辨率
self.layer.rasterizationScale = [UIScreen mainScreen].scale;
3.cell里不使用block
delegate運行成本低,block成本很高。
cell里的回調(diào)事件通過delegate處理,cell由于復(fù)用會反復(fù)執(zhí)行賦值操作。