ios view 切上部分圆角_iOS开发-View切圆角

本文介绍了在iOS开发中如何为视图设置圆角,包括使用系统默认方式设置四个角的圆角以及自定义方式实现特定角的圆角效果。通过设置`clipsToBounds`和`cornerRadius`属性,以及利用`UIBezierPath`和`CAShapeLayer`进行自定义裁剪,可以实现如顶部左右圆角的效果。

//OC对应的系统和自定义切圆角

///默认切四个角的圆角

// v.clipsToBounds = YES;

// v.layer.cornerRadius = 8;

//自定义切多个角圆角

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:v.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(8, 8)];

CAShapeLayer *maskLayer = [CAShapeLayer new];

maskLayer.frame = v.bounds;

maskLayer.path = maskPath.CGPath;

v.layer.mask = maskLayer;

//Swift对应的系统和自定义切圆角

let v = UIView.init(frame: CGRect.init(x: 100, y: 100, width: 100, height: 100));

v.backgroundColor = UIColor.cyan;

v.layer.masksToBounds = true;

v.layer.cornerRadius = 8;

self.view.addSubview(v);

let v2 = UIView.init(frame: CGRect.init(x: 300, y: 100, width: 100, height: 100));

v2.backgroundColor = UIColor.red;

self.view.addSubview(v2);

let maskpath = UIBezierPath.init(roundedRect: v2.bounds, byRoundingCorners:[.bottomLeft , .topLeft , .bottomRight], cornerRadii: CGSize.init(width: 4, height: 4))

let maskLayer = CAShapeLayer.init()

maskLayer.frame = v2.bounds;

maskLayer.path = maskpath.cgPath;

v2.layer.mask = maskLayer

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值