图层混合查看:运行项目,在Xcode9->Debug->view Debugging->Rendering勾选Color Blened Layers
1.label的处理
label.backgroundColor = [UIColor whiteColor];
label.layer.masksToBounds = YES;
控件不发生形变的时候masksToBounds是不会触发离屏渲染的
2.图片处理
/**
重新绘制image
@param sourceImage <#sourceImage description#>
@param size <#size description#>
@return <#return value description#>
*/
- (UIImage *)drawImage:(UIImage *)sourceImage size:(CGSize)size color:(UIColor *)color {
if (!sourceImage) {
return nil;
}
CGRect bounds = CGRectMake(0, 0, size.width, size.height);
// 开启图形上下文 size:绘图的尺寸 opaque:不透明 scale:屏幕分辨率系数,0会选择当前设备的屏幕分辨率系数
UIGraphicsBeginImageContextWithOptions(bounds.size, true, 0);
// 背景颜色填充
[color setFill];
UIRectFill(bounds);
[sourceImage drawInRect:bounds];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
经验来自:
1、https://blog.6ag.cn/1762.html