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.
}
相关推荐
—Qeyser20 小时前
Flutter 颜色完全指南
android·flutter·ios
2501_9160088921 小时前
iOS 上架需要哪些准备,账号、Bundle ID、证书、描述文件、安装测试及上传
android·ios·小程序·https·uni-app·iphone·webview
Zender Han1 天前
Flutter Android 启动页 & App 图标替换(不使用任何插件的完整实践)
android·flutter·ios
—Qeyser1 天前
Flutter CustomScrollView 自定义滚动视图 - 完全指南
android·flutter·ios
软件小滔1 天前
我使用MAC WiFi Explorer Pro完成了一次家庭网络“大扫除”
网络·macos·智能路由器·mac·应用推荐·wifi explorer
不爱吃糖的程序媛1 天前
Kuikly-OH 实践(mac版本)
macos
活蹦乱跳酸菜鱼1 天前
MAC 发出的一个帧(MAC Frame)及其完整的帧格式
网络·macos
—Qeyser1 天前
Flutter ListView 列表组件完全指南
android·flutter·ios
qq_448011161 天前
Mac手动删除应用
macos
游戏开发爱好者81 天前
如何在 Windows 环境下测试 iOS App,实时日志,CPU监控
android·ios·小程序·https·uni-app·iphone·webview