This extension provides the ability to easily create a UIButton with a flat style, a border or both.
To learn more about this project, please visit it on GitHub.
Give UIButtonFlat a try without having to type a single line of code with the UIButtonFlat Demo.
Simply add UIButtonFlat via Swift Package Manager to your project... that's it!
You can choose to create a UIButtonFlat control in the same way that you would create a stock UIButton control, either via Storyboards, programmatically or through a mixture of the two.
- Select the UIButton that you wish to use
- Switch to the Identity Inspector
- Update the UIButton's class to 'UIButtonFlat'
- Switch to the Attributes Inspector
- Switch Type to 'Custom'
- You can find the configuration options under the Button Flat heading
Import UIButtonFlat
. Then create a UIButtonFlat control in the same way that you would create a UIButton control, except that instead of using UIButton, use the UIButtonFlat type. Because UIButtonFlat in an extension of UIButton, all of UIButton's functions will be inherited. Please note that if you are creating a UIButtonFlat from scratch and not connecting to a button that you've either fully or partially configured in a Storyboard, you will need to declare it's type as .custom
like so:
let button: UIButtonFlat = UIButtonFlat(type: .custom)
Attribute | Type | Default | Description |
---|---|---|---|
flatBackground | Bool | false | Determines if a flat background will be drawn |
border | Bool | false | Determines if a border will be drawn |
borderColor | UIColor | .clear | The color of the border |
borderWidth | CGFloat | 1 | The width of the border |
corner | Bool | false | Determines if a rounded corner will be applied |
cornerRadius | CGFloat | 0 | The radius of the corner |
backgroundColor | UIColor | self.view.backgroundColor | The color used when drawing a flat background |
textColor | UIColor | .white | The color used by the title label; overrides titleLabel.textColor |
- None