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.
}
相关推荐
末代iOS程序员华仔5 小时前
iOS 5.6 条例解决方法
flutter·ios·swift
OsDepK5 小时前
xcode应用构建至testflight测试流程
ide·macos·xcode
末代iOS程序员华仔11 小时前
Guideline 5.6 - Developer Code of Conduct
flutter·ios·swift
guo_wen_qiang12 小时前
一个好用的命令——查看文件大小
linux·macos
2501_9159184112 小时前
Flutter项目配置iOS混淆的详细步骤与工具推荐
android·flutter·ios·小程序·uni-app·cocoa·iphone
凡泰AI13 小时前
如何通过小程序多端框架,让一个小程序同时运行在iOS、安卓、鸿蒙和微信客户端,实现开发层面的降本增效
android·ios·微信小程序·小程序·harmonyos
阿童木写作1 天前
跨境电商图片翻译工具推荐:批量图片翻译+视频字幕翻译+智能抠图
python·macos·音视频·xcode
2501_915106321 天前
安卓抓包软件2026,免证书抓包 应用层抓包 代理抓包全解析
网络协议·计算机网络·网络安全·ios·adb·https·udp
kango1 天前
Xcode、模拟器Runtime、真机符号完整知识手册
ios·app
攀小黑1 天前
vue3+Web Speech API 封装了一个弹窗语音输入
前端·macos·xcode