美文网首页
ios-给view添加部分圆角

ios-给view添加部分圆角

作者: 码农_会写诗 | 来源:发表于2020-08-11 16:58 被阅读0次

    简单粗暴点  直接上代码吧

    -(void)createUI{
       
        UIView * view1 = [[UIView alloc]initWithFrame:CGRectMake(50, 120, 100, 100)];
        view1.backgroundColor = [UIColor grayColor];
        [self.view addSubview:view1];
       
        CGFloat radius = 15; // 圆角大小
        UIRectCorner corner = UIRectCornerTopLeft | UIRectCornerBottomLeft; // 圆角位置
        UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:view1.bounds byRoundingCorners:corner cornerRadii:CGSizeMake(radius, radius)];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = view1.bounds;
        maskLayer.path = path.CGPath;
        view1.layer.mask = maskLayer;
       
    }

    相关文章

      网友评论

          本文标题:ios-给view添加部分圆角

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