镂空效果

2016-08-23  本文已影响39人  Mustard_Buli

好久都没有记录东西了,今天写一种最简单的镂空的实现方式,之所以会写到这个样式,是因为想做到像微信扫一扫的那个界面。

- (void)addRect {
    
    //背景
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:[UIScreen mainScreen].bounds cornerRadius:0];
    //镂空,这里可以根据具体的需求定义镂空的样式(🌰,圆、三角之类的)
    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)的区域有一个镂空的效果。

上一篇 下一篇

猜你喜欢

热点阅读