wefagaefesfsefsef wefagaefesfsefsef - 3 months ago 8
iOS Question

Objective-C: create button without fill

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

image

Answer

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)
Comments