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.
}
相关推荐
JERRY. LIU4 小时前
Mac 笔记本通用快捷键大全
linux·macos
all79807969711 小时前
黑苹果macos 15 Sequoia升级 macos 26.1 Tahoe小结
macos
唯一浩哥12 小时前
2026 年,macbook air 2015 升级注意事项
macos·macbook·macbook air 2015·升级硬盘
TheNextByte114 小时前
如何将文件从Android无线传输到 iPad
android·ios·ipad
2501_9151063216 小时前
如何在iPad上高效管理本地文件的完整指南
android·ios·小程序·uni-app·iphone·webview·ipad
2501_9151063217 小时前
iOS 成品包加固,在只有 IPA 的情况下,能做那些操作
android·ios·小程序·https·uni-app·iphone·webview
Free Tester18 小时前
在iPhone上显示点击屏幕点击的方法
功能测试·ios·iphone
AALoveTouch18 小时前
某麦APP抢票技术解析实现
android·ios
云和数据.ChenGuang1 天前
CANN实现语音积分程序的测试
ide·macos·ai·cann·人工智能识别语音
2501_915909061 天前
苹果iOS应用上架详细流程与注意事项解析
android·ios·小程序·https·uni-app·iphone·webview