Strange artifacts when using UIButton with corner radius set

780 views Asked by At

I am using a standard UIBUtton where I set border width and a corner radius such as

[button1.layer setCornerRadius: 15.0];
[button1.layer setMasksToBounds:TRUE];
[button1.layer setBorderWidth: 8.0];

As you can see, there are strange artifacts appearing around the rounded corners of the button. Are there any way to get rid of them other then drawing the button manually? enter image description here

2

There are 2 answers

0
CocoaAficionado On BEST ANSWER

At the end of the day, the solution that worked for me was to set the border width of the buttons to 0 and then simply draw them on the white background view at the proper offsets. Couldn't take advantage of UIButton's border taking care of the white spacing around each button, but the artifacts are obviously gone.

enter image description here

0
Nick Terry On

I'm not sure why that's happening, and there may be an easier solution, but you can use a CAShapeLayer mask to render an image within a certain shape.

See this answer for code on how to so. https://stackoverflow.com/a/18515698/2700842