设置UIView圆角的拓展

来源:互联网 发布:python pip yum源 编辑:程序博客网 时间:2024/06/10 09:06
@interface UIView (RectCorner)    

@end    

@implementation UIView (RectCorner)

//对于左右上角的圆角修饰

 - (void)setCornerOnTop 
{     
         UIBezierPath *maskPath;     
         maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds   byRoundingCorners:(UIRectCornerTopLeft |                              UIRectCornerTopRight)  cornerRadii:CGSizeMake(10.0f, 10.0f)];      
         CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];     
         maskLayer.frame = self.bounds;     
         maskLayer.path = maskPath.CGPath;      
         self.layer.mask = maskLayer;     
        [maskLayer release];  
}
//对于左右下角的圆角的修饰

 - (void)setCornerOnBottom 
{      
         UIBezierPath *maskPath;     
         maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds   byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(10.0f, 10.0f)];      
         CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];     
         maskLayer.frame = self.bounds;     
        maskLayer.path = maskPath.CGPath;   
         self.layer.mask = maskLayer;     
         [maskLayer release];  
}  
//对于所有的圆角进行修饰
- (void)setAllCorner
 {     
         UIBezierPath *maskPath;     
         maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:10.0];     
         CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];     
         maskLayer.frame = self.bounds;     
         maskLayer.path = maskPath.CGPath;      
         self.layer.mask = maskLayer;     
        [maskLayer release];  
}
//不修饰

 - (void)setNoneCorner
{      
         self.layer.mask = nil;  
}    

@end


//重写view的类目

#import "UIView+Corner.h"

@implementation UIView (Corner)

-(void)addCornerType:(UIRectCorner)corners AndCornerSize:(CGSize)size

{

    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:size];

    CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];

    maskLayer.frame = self.bounds;

    maskLayer.path = maskPath.CGPath;

    self.layer.mask = maskLayer;

}

@end



0 0
原创粉丝点击