iOS 实现视图遮罩效果

有时候,我们会遇到这种需求,只讲视图的某个部分展示出来

这时候,我们可以通过设置该视图layer.mask = layerb来实现,需要注意的是,这里的layerb必须要设置backgroundColor,渐变layer有colors,否则达不到效果

示例:

复制代码
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor cyanColor];
    
    CALayer *layer = [[CALayer alloc] init];
    layer.frame = CGRectMake(100, 200, 100, 100);
    layer.backgroundColor = [UIColor whiteColor].CGColor;
    self.view.layer.mask = layer;
    // Do any additional setup after loading the view.
}
相关推荐
新镜1 天前
【Flutter】LTR/RTL 阿拉伯语言/希伯来语言
android·flutter·ios·客户端
2501_915909061 天前
设置了 SSL Pinning 与双向 TLS 验证要怎么抓包
网络·网络协议·ios·小程序·uni-app·iphone·ssl
Three~stone1 天前
MacOS 各个版本相关镜像(dng和iso镜像文件)
macos
爱喝矿泉水的猛男1 天前
如何测试鼠标是否支持mac mouse fix
macos·计算机外设
2501_916007472 天前
如何查看 iOS 设备系统与硬件信息,iOS系统信息显示工具
android·ios·小程序·https·uni-app·iphone·webview
Navicat中国2 天前
Navicat Premium MacOS:原生或通过 Rosetta 运行教程
数据库·macos·oracle·navicat·rosetta
2501_916007472 天前
iOS APP 开发,从项目创建、证书与描述文件配置、安装测试和IPA 上传
android·ios·小程序·https·uni-app·iphone·webview
Siyu_Zhu2 天前
mac + server 完全一致的实验模板
macos
TESmart碲视2 天前
KVM切换器支持高刷新率游戏吗?
游戏·macos·计算机外设·kvm切换器·双屏kvm切换器
Swift社区2 天前
在Swift中实现允许重复的O(1)随机集合
开发语言·ios·swift