美文网首页
使用UIBezierPath和CAShapeLayer给view

使用UIBezierPath和CAShapeLayer给view

作者: Fisher123 | 来源:发表于2017-12-29 22:42 被阅读8次

    使用前导入框架AVFoundation

    - (void)viewDidLoad {
        [super viewDidLoad];
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
        view.backgroundColor = [UIColor redColor];
        
        UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:view.bounds.size];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
        maskLayer.frame = view.bounds;
        maskLayer.path = maskPath.CGPath;
        view.layer.mask = maskLayer;
        
        [self.view addSubview:view];
    }
    
    

    相关文章

      网友评论

          本文标题:使用UIBezierPath和CAShapeLayer给view

          本文链接:https://www.haomeiwen.com/subject/ldgwgxtx.html