Applying Rounded Corners to a View in Objective-C
In some instances it may be necessary to apply some lovely rounded corners to a UIView or one of its subclasses when building an iOS app. In some instances it is ok to access the layer property of the view and call setCornerRadius.
If performance suffers then using bezierPaths and masks can be the solution.
-(void) setCornerRadius
{
// Create a bezier path with the required corners rounded
UIBezierPath *cornersPath = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:(UIRectCornerBottomLeft|UIRectCornerBottomRight) cornerRadii:CGSizeMake(5, 5)];
//Create a new layer to use as a mask
CAShapeLayer *maskLayer = [CAShapeLayer layer];
// Set the path of the layer
maskLayer.path = cornersPath.CGPath;
self.view.layer.mask = maskLayer;
}Written by Paul Morris
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Uiview
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#