iPhone iPhone - 1 year ago 60
iOS Question

How to create border in UIButton?

I use custom button in my app named "addButton" and I want to border it with white color how can i get the white color border around my custom button?

Answer Source

You can set the border properties on the CALayer by accessing the layer property of the button.

First, add Quartz

#import <QuartzCore/QuartzCore.h>

Set properties:

[[myButton layer] setBorderWidth:2.0f];
[[myButton layer] setBorderColor:[UIColor greenColor].CGColor];



The CALayer in the link above allows you to set other properties like corner radius, maskToBounds etc...

Also, a good article on button fun: