好久都沒有記錄東西了,今天寫一種最簡單的鏤空的實現(xiàn)方式,之所以會寫到這個樣式,是因為想做到像微信掃一掃的那個界面。
- (void)addRect {
//背景
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:[UIScreen mainScreen].bounds cornerRadius:0];
//鏤空,這里可以根據(jù)具體的需求定義鏤空的樣式(??,圓、三角之類的)
UIBezierPath *rectPath = [UIBezierPath bezierPathWithRect:CGRectMake(100, 100, 100, 100)];
[path appendPath:rectPath];
[path setUsesEvenOddFillRule:YES];
CAShapeLayer *fillLayer = [CAShapeLayer layer];
fillLayer.path = path.CGPath;
fillLayer.fillRule = kCAFillRuleEvenOdd;
fillLayer.fillColor = [UIColor blackColor].CGColor;
fillLayer.opacity = 0.5;
[self.view.layer addSublayer:fillLayer];
}
這樣就可以在屏幕上(100, 100, 100, 100)的區(qū)域有一個鏤空的效果。