wefagaefesfsefsef wefagaefesfsefsef - 1 year ago 56
iOS Question

Objective-C: create button without fill

How to create rounded button programmatically without fill like on image?

image

Answer Source

You can use some of the layer properties to add on outline to any UIView (UIButton is a subclass of UIView)

Objective-C

UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.layer.borderWidth = 2.0;
button.layer.borderColor = [UIColor blueColor].CGColor;
button.layer.cornerRadius = 2.0;
[button setTitle:@"Outline Button" forState:UIControlStateNormal];

Swift

let button = UIButton(type: .System)
button.layer.borderWidth = 2.0
button.layer.borderColor = UIColor.blueColor().CGColor
button.layer.cornerRadius = 2.0
button.setTitle("Outline Button", forState: .Normal)