- 设置圆角
-(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.在指定区域拉伸屏幕
[image drawInRect:rect];
//3.绘制内切的圆形
[[UIColor darkGrayColor] setStroke];
path.lineWidth = 2;
[path stroke];
//4.获取image
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
//5.关闭上下文
UIGraphicsEndImageContext();
return result;
}
- 栅格化
缺点耗电会增加
//异步绘制
self.layer.drawsAsynchronously = YES;
//栅格化
self.layer.shouldRasterize = YES;
//指定分辨率
self.layer.rasterizationScale = [UIScreen mainScreen].scale;
3.cell里不使用block
delegate运行成本低,block成本很高。
cell里的回调事件通过delegate处理,cell由于复用会反复执行赋值操作。
网友评论