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.
}
相关推荐
2501_915106322 小时前
Perfdog 成本变高之后,Windows 上还能怎么做 iOS APP 性能测试
android·ios·小程序·https·uni-app·iphone·webview
2501_915106323 小时前
iOS 安装了证书,HTTPS 还是抓不到
android·网络协议·ios·小程序·https·uni-app·iphone
2501_924064114 小时前
2026年移动应用渗透测试流程方案及iOS与Android框架对比
android·ios
扑火的小飞蛾4 小时前
【macOS】n8n 安装配置笔记
笔记·macos
Digitally4 小时前
如何轻松地将数据从 iPhone 传输到 iPhone 17
ios·iphone
2501_916007475 小时前
iOS 自动化上架的工具组合,在多平台环境中实现稳定发布
android·运维·ios·小程序·uni-app·自动化·iphone
TO_ZRG5 小时前
iOS 符号表文件概要
macos·ios·cocoa
默默在路上5 小时前
M芯片使用VMware Fusion安装CentOS Stream 9教程
linux·macos·centos
TheNextByte16 小时前
如何在Mac上收发Android信息 [2026 指南]
android·macos
耘田6 小时前
 macOS Launch Agent 定时任务实践指南
java·开发语言·macos