首页 > 代码库 > ios 给uiview创作遮罩

ios 给uiview创作遮罩

mask一定是PNG格式的图像,去掉背景 .jpg格式图片没有alpha values

遮罩是通过图片透明度的信息实现与颜色无关

UIImage*_maskingImage =[UIImage imageNamed:@"mask"];
CALayer*_maskingLayer =[CALayer layer];
_maskingLayer
.frame = theView.bounds;
[_maskingLayer setContents:(id)[_maskingImage CGImage]];
[theView.layer setMask:_maskingLayer];