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.
}
相关推荐
Hical_W1 天前
Hical 踩坑实录五部曲(二):MSVC / GCC / Clang 三平台 C++20 编译差异
linux·windows·经验分享·嵌入式硬件·macos·开源·c++20
代码的小搬运工1 天前
UITableView
开发语言·ui·ios·objective-c
wjhx1 天前
关于xcode中使用图标
ide·macos·xcode
互联网行业信息差1 天前
iOS开发常见问题与最新工具使用心得
macos·ios·cocoa
MonkeyKing1 天前
iOS Tagged Pointer 原理、判断方式、适用场景与避坑指南
ios
wuxianda10301 天前
Object-C/Swift/UniApp项目苹果商店上架3天极速解决方案汇报总结
ios·uni-app·objective-c·cocoa·苹果上架
鹤卿1231 天前
UI----多界面传值
ui·ios
清泉Kikyō1 天前
Mac使用vscode claude 插件使用 deepseek flash
macos·deepseek
UnicornDev1 天前
从零开始学iOS开发(第四十七篇):Core Haptics 触感反馈 —— 让应用拥有真实的触觉体验
ios
一块小土坷垃1 天前
## BetterTouchTool 5.736 特别版 – macOS 触控板增强工具深度体验
macos·开源软件