有时候,我们会遇到这种需求,只讲视图的某个部分展示出来
这时候,我们可以通过设置该视图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.
}











![代码随想录算法训练营第五天:哈希表的初步认识[1]](https://img-blog.csdnimg.cn/img_convert/093550d0bfd4dd3312564ac3e67469ab.png)








