Adil's Personal Blog

Using octopress! A blogging framework for hackers.

Creating a View With a Single Rounded Corner in iOS

| Comments

In another note of mine, I discussed how you can have UIView with rounded corners but what if you only need one rounded corner? To achieve that goal, following code snippet will help you in that.

1
2
3
4
5
6
7
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view.bounds
                                               byRoundingCorners:UIRectCornerBottomLeft];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = view.bounds;
maskLayer.path = maskPath.CGPath;
view.layer.mask = maskLayer;
[maskLayer release];  // For non-ARC code

This code snippet will make the bottom left corner round. If you want to have bottom right corner, replace UIRectCornerBottomLeft with UIRectCornerBottomRight, to have top left corner round, replace it with UIRectCornerTopLeft and to have top right corner round, replace it with UIRectCornerTopRight.

Comments