Amr Fawaz
Amr Fawaz

Reputation: 13

How to set radius for bottom corners only

enter image description here

How would I set a radius for only the bottom two corners, like in the image above?

Upvotes: 0

Views: 111

Answers (2)

Glenn Posadas
Glenn Posadas

Reputation: 13281

It's been literally MONTHS since the last time I've wrote an Objective-c code, since I want to tray it again, here's the Objective-c version of Mago Nicolas Palacios' answer written in Swift 3.0.

UIImageView *sampleImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sample"]];
CGSize size = CGSizeMake(30, 30);
UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:sampleImage.bounds
                                                 byRoundingCorners:(UIRectCornerBottomRight | UIRectCornerTopLeft)
                                                       cornerRadii:size];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
[shapeLayer setPath:[bezierPath CGPath]];
sampleImage.layer.mask = shapeLayer;

Upvotes: 2

Mago Nicolas Palacios
Mago Nicolas Palacios

Reputation: 2591

I have just done that (For Swift 3, but it might help you as well), You should have an outlet to your image, for example called yourImage and then do this On viewDidLoad:

    let shapeLayer = CAShapeLayer()
   shapeLayer.path = UIBezierPath(roundedRect: yourImage.bounds, byRoundingCorners: [.bottomLeft, .bottomRight], cornerRadii: CGSize(width: 30, height: 30)).cgPath
yourImage.layer.mask = shapeLayer

Upvotes: 2

Related Questions