指定视图的圆角个数

平常设置视图的圆角最普遍的就是设置四个角的,方法也就是一句代码解决:

view.layer.cornerRadius = 10;


四个圆角

但有时需求会是指定某个,或者特定哪几个角设置圆角,所以我们需要不一样的解决方法:

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(50, 150, 60, 60)];     
view.backgroundColor = [UIColor orangeColor];    
// UIRectCornerTopLeft      左上角     
// UIRectCornerTopRight     右上角     
// UIRectCornerBottomLeft   左下角     
// UIRectCornerBottomRight  右下角     
// UIRectCornerAllCorners   四个角     
// byRoundingCorners: 参数可以选择上面五种,需要制定某几个角为圆角,就要用 “|” 组合     
// cornerRadii: 代表圆角值大小     
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];     
maskLayer.frame = view.bounds;     
maskLayer.path = maskPath.CGPath;     
view.layer.mask = maskLayer;     
[self.view addSubview:view];


左上和右下

此方法可以适用很多种视图,比如UIViewUILabelUIImageViewUIButton等。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值