Simple UIButton subclass with animated, state-aware attributes. Easy to subclass and configure!
![Sample](Resources/example.gif)Just create your own SimpleButton
subclass and configure your button attributes by overriding configureButtonStyles
.
@IBDesignable
class PrimaryButton: SimpleButton {
override func configureButtonStyles() {
super.configureButtonStyles()
setBorderWidth(4.0, forState: .Normal)
setBackgroundColor(UIColor(red: 52/255, green: 73/255, blue: 94/255, alpha: 1.0), forState: .Normal)
setBackgroundColor(UIColor(red: 44/255, green: 62/255, blue: 80/255, alpha: 1.0), forState: .Highlighted)
setBorderColor(UIColor(red: 44/255, green: 62/255, blue: 80/255, alpha: 1.0), forState: .Normal)
setScale(0.98, forState: .Highlighted)
setTitleColor(UIColor.whiteColor(), forState: .Normal)
}
}
Just set the new custom button class to a button in Interface Builder's property inspector.
![Sample](Resources/property_inspector.png)Your buttons are even rendered live within Interface Builder. ✨ Some attributes, like corner radius, border width and border color, can be set directly from within Interface Builder.
You can also configure your button directly from code
let awesomeButton = SimpleButton(type:.Custom)
awesomeButton.setBorderWidth(2.0, forState: .Normal)
awesomeButton.setBorderColor(UIColor.redColor(), forState: .Highlighted)
awesomeButton.animationDuration = 0.3
Default is 0.1
scale
backgroundColor
borderWidth
borderColor
cornerRadius
simpleButton.setScale(0.98, forState: .Highlighted)
simpleButton.setScale(0.80, forState: .Disabled)
simpleButton.setBackgroundColor(UIColor(red: 52/255, green: 73/255, blue: 94/255, alpha: 1.0), forState: .Normal)
simpleButton.setBackgroundColor(UIColor(red: 44/255, green: 62/255, blue: 80/255, alpha: 1.0), forState: .Highlighted)
simpleButton.setBackgroundColor(UIColor.grayColor(), forState: .Disabled)
simpleButton.setBorderWidth(4.0, forState: .Normal)
simpleButton.setBorderWidth(2.0, forState: .Highlighted)
simpleButton.setBorderWidth(4.0, forState: .Normal)
simpleButton.setBorderColor(UIColor(red: 230/255, green: 126/255, blue: 34/255, alpha: 1.0), forState: .Normal)
simpleButton.setBorderColor(UIColor(red: 149/255, green: 165/255, blue: 166/255, alpha: 1.0), forState: .Highlighted)
simpleButton.setCornerRadius(10, forState: .Normal)
simpleButton.setCornerRadius(20, forState: .Highlighted)
Note that SimpleButton is written in swift 2.0
and may not be compatible with previous versions of swift.
Add the following line to your Cartfile.
github "aloco/SimpleButton"
Then run carthage update
.
Just drag and drop the SimpleButton.swift
file into your project.
- Create something awesome, make the code better, add some functionality, whatever (this is the hardest part).
- Fork it
- Create new branch to make your changes
- Commit all your changes to your branch
- Submit a pull request