iOS|iOS CALayer mask 属性
/* A layer whose alpha channel is used as a mask to select between the * layer's background and the result of compositing the layer's * contents with its filtered background. Defaults to nil. When used as * a mask the layer's `compositingFilter' and `backgroundFilters' * properties are ignored. When setting the mask to a new layer, the * new layer must have a nil superlayer, otherwise the behavior is * undefined. Nested masks (mask layers with their own masks) are * unsupported. */ @property(strong) CALayer *mask;
以上是CALayer的头文件关于mask的说明,mask实际上layer内容的一个遮罩。
如果我们把mask是透明的,实际看到的layer是完全透明的,也就是说只有mask的内容不透明的部分和layer叠加的部分才会显示出来,
效果如下
【iOS|iOS CALayer mask 属性】
func addShapeView() -> Void {let wdthLabel = createLabel(rect: CGRect.init(x: 100, y: 100, width: 100, height: 100), text: "这是一个label");
wdthLabel.textColor = UIColor.darkGray;
wdthLabel.font = fontSize(size: 20);
titlDb = createLabel(rect: CGRect.init(x: 100, y: 100, width: 100, height: 100), text: "这是一个label");
titlDb.textColor = UIColor.green;
titlDb.font = fontSize(size: 20);
//titlDb.backgroundColor = UIColor.orange;
maskLayer = CATextLayer();
maskLayer.frame = CGRect.init(x: 0, y: 0, width: 100, height: 100);
maskLayer.backgroundColor = UIColor.clear.cgColor;
//maskLayer.string = "这是一个label";
maskLayer.foregroundColor = UIColor.blue.cgColor;
maskLayer.fontSize = 20;
maskLayer.backgroundColor = UIColor.blue.cgColor;
titlDb.layer.mask = maskLayer;
//label.layer.addSublayer(bcakItem);
}
var titlDb: UILabel!
var maskLayer: CATextLayer!
推荐阅读
- 2020-04-07vue中Axios的封装和API接口的管理
- iOS中的Block
- 记录iOS生成分享图片的一些问题,根据UIView生成固定尺寸的分享图片
- 2019-08-29|2019-08-29 iOS13适配那点事
- Hacking|Hacking with iOS: SwiftUI Edition - SnowSeeker 项目(一)
- iOS面试题--基础
- 接口|axios接口报错-参数类型错误解决
- iOS|iOS 笔记之_时间戳 + DES 加密
- iOS,打Framework静态库
- 常用git命令总结