美文网首页
iOS指定视图任意角为圆角

iOS指定视图任意角为圆角

作者: Desert_Eagle | 来源:发表于2018-02-06 10:11 被阅读0次
        CGFloat containerViewW = 200;
        CGFloat containerViewH = 200;
        CGFloat containerViewX = (self.view.bounds.size.width - containerViewW) / 2;
        CGFloat containerViewY = (self.view.bounds.size.height - containerViewH) / 2;
        UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(containerViewX, containerViewY, containerViewW, containerViewH)];
        containerView.backgroundColor = [UIColor blueColor];
        [self.view addSubview:containerView];
        
        /* 指定哪个角为圆角:
                         UIRectCornerTopLeft:左上    
                         UIRectCornerTopRight:右上  
                         UIRectCornerBottomLeft:左下  
                         UIRectCornerBottomRight:右下
         */
        UIRectCorner corners = UIRectCornerTopLeft | UIRectCornerTopRight;
        UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:containerView.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(20, 20)];
        CAShapeLayer *shapeLayer = [CAShapeLayer layer];
        shapeLayer.path = path.CGPath;
        
        containerView.layer.mask = shapeLayer;
    

    相关文章

      网友评论

          本文标题:iOS指定视图任意角为圆角

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