I am using the following code to make UITextField's/UIView's Top corners rounded, but the problem is only left top corner is getting rounded. What I am doing wrong or is there any other way to do so.
- (void)roundCornersOnView:(UIView*)view onTopLeft:(BOOL)tl topRight:(BOOL)tr bottomLeft:(BOOL)bl bottomRight:(BOOL)br radius:(float)radius
{
if (tl || tr || bl || br) {
UIRectCorner corner = 0; //holds the corner
//Determine which corner(s) should be changed
if (tl) {
corner = corner | UIRectCornerTopLeft;
}
if (tr) {
corner = corner | UIRectCornerTopRight;
}
if (bl) {
corner = corner | UIRectCornerBottomLeft;
}
if (br) {
corner = corner | UIRectCornerBottomRight;
}
UIView* roundedView = view;
UIBezierPath* maskPath = [UIBezierPath bezierPathWithRoundedRect:roundedView.bounds byRoundingCorners:corner cornerRadii:CGSizeMake(radius, radius)];
CAShapeLayer* maskLayer = [CAShapeLayer layer];
maskLayer.frame = roundedView.bounds;
maskLayer.path = maskPath.CGPath;
roundedView.layer.mask = maskLayer;
}
}
Calling the above method
[self roundCornersOnView:textField onTopLeft:YES topRight:YES bottomLeft:NO bottomRight:NO radius:5.0];