设置UIView圆角的拓展

来源:互联网 发布:snapchat网络无法连接 编辑:程序博客网 时间:2024/06/10 04:09
  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
原创粉丝点击