Tuesday, 8 April 2014

UIView with rounded corners


#import <QuartzCore/QuartzCore.h>



1)  self.viewTest.layer.cornerRadius = 15.0;
    self. viewTest.layer.borderWidth = 1.0;
     self. viewTest.layer.borderColor = [UIColor redColor].CGColor;
    self. viewTest.layer.masksToBounds = YES;



2) 

+(void)roundView:(UIView *)view onCorner:(UIRectCorner)rectCorner radius:(float)radius
{
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view.bounds
                                                   byRoundingCorners:rectCorner
                                                         cornerRadii:CGSizeMake(radius, radius)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = view.bounds;
    maskLayer.path = maskPath.CGPath;
    [view.layer setMask:maskLayer];
}

The cool part about it is that you can select which corners you want rounded up.

No comments:

Post a Comment