设置UIView圆角的拓展

  1. @interface UIView (RectCorner)  
  2.   
  3. @end  
  4.   
  5. @implementation UIView (RectCorner)  
  6. - (void)setCornerOnTop {  
  7.     UIBezierPath *maskPath;  
  8.     maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds  
  9.                                      byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight)  
  10.                                            cornerRadii:CGSizeMake(10.0f10.0f)];  
  11.     CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];  
  12.     maskLayer.frame = self.bounds;  
  13.     maskLayer.path = maskPath.CGPath;  
  14.     self.layer.mask = maskLayer;  
  15.     [maskLayer release];  
  16. }  
  17. - (void)setCornerOnBottom {  
  18.     UIBezierPath *maskPath;  
  19.     maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds  
  20.                                      byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight)  
  21.                                            cornerRadii:CGSizeMake(10.0f10.0f)];  
  22.     CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];  
  23.     maskLayer.frame = self.bounds;  
  24.     maskLayer.path = maskPath.CGPath;  
  25.     self.layer.mask = maskLayer;  
  26.     [maskLayer release];  
  27. }  
  28. - (void)setAllCorner {  
  29.     UIBezierPath *maskPath;  
  30.     maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds  
  31.                                           cornerRadius:10.0];  
  32.     CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];  
  33.     maskLayer.frame = self.bounds;  
  34.     maskLayer.path = maskPath.CGPath;  
  35.     self.layer.mask = maskLayer;  
  36.     [maskLayer release];  
  37. }  
  38. - (void)setNoneCorner{  
  39.     self.layer.mask = nil;  
  40. }  
  41.   
  42. @end 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值