代碼
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor clearColor];
UIBezierPath *path = [UIBezierPath bezierPathWithRect:self.view.bounds];
// 創(chuàng)建矩形
UIBezierPath *circlePath = [UIBezierPath bezierPathWithRect:CGRectMake(self.view.bounds.size.width / 2 - 100, self.view.bounds.size.height / 2 - 150, 200, 200)];
[path appendPath:circlePath];
CAShapeLayer *shaperLayer = [CAShapeLayer layer];
shaperLayer.frame = self.view.bounds;
shaperLayer.fillColor = [UIColor dd_hexStringToColor:@"000000" alpha:0.3].CGColor;
// 設(shè)置填充規(guī)則
shaperLayer.fillRule = kCAFillRuleEvenOdd;
shaperLayer.path = path.CGPath;
[self.view.layer addSublayer: shaperLayer];
}
效果
6EA2810BB4DD61E59AC0AD376000833F 2.jpg
拓展
一篇關(guān)于UIBezierPath,CAShapeLayer等使用場景的參考
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者