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.
}
相关推荐
_瑞7 小时前
深入理解 iOS 渲染原理
前端·ios
Android出海16 小时前
iOS 出海新门槛:未成年人合规来了
ios·app store·ios开发·苹果开发者·ios开发者·ios出海
2501_9151063216 小时前
iOS 软件测试工具性能监控、日志分析 KeyMob、Instruments等
android·ios·小程序·https·uni-app·iphone·webview
木叶丸17 小时前
AI 编程概念与 Harness 工程实践入门
人工智能·flutter·ios
zzb158018 小时前
Zed 配置 Swift / iOS 开发
开发语言·ios·swift
全堆鸿蒙1 天前
25 数据库设计与表结构规划:5 张表的设计思路
数据库·华为·cocoa·harmonyos
colman wang2 天前
Git指令(Mac)
git·macos
黑科技iOS上架2 天前
如何解决AppStore Guideline 5.6被拒
经验分享·ios·ai编程
韩曙亮2 天前
【Flutter】iOS 网络权限设置 ① ( WLAN/蜂窝全局联网权限设置 )
网络·flutter·ios·网络权限
Geek-Chow2 天前
Mobile App Certificate Pinning: Underlying Principle and a Swift Example
开发语言·ios·swift·安全架构