Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Corner radius issue with UIButton

I want to add a corner radius to a UIButton. It is working fine but a problem occurs when I add image to it.

It does not round its corners with images, the image is shown in full rectangle form.

Please see the image, I have used the corner radius with red color and the output is as follow:

enter image description here

Please help.

like image 565
Kumar sonu Avatar asked Apr 14 '11 08:04

Kumar sonu


2 Answers

Did you try to use set the masksToBounds: property? Fore example:

CALayer *layer = [myView layer];
[layer setMasksToBounds:YES];
[layer setCornerRadius:8.0];

That should do the trick.

like image 97
Wolfgang Schreurs Avatar answered Oct 16 '22 14:10

Wolfgang Schreurs


you use -

myButton.imageView.layer.cornerRadius = 5;

but make sure that your image size is exact same as button size. its working for me.

like image 33
Abhijeet Barge Avatar answered Oct 16 '22 15:10

Abhijeet Barge