AddButton
is a simple button which has two states. One will display an add sign, the other a checkmark.
To run the example project, clone the repo, and run pod install
from the Example directory first.
To use AddButton
in your own project simply take a UIView
object and set its class to AddButton
. You can customize various properties directly in Interface Builder like the strokeColor
or lineWidth
.
// create an AddButton and add it as a subview
let addButton = AddButton(frame: CGRect(x: 50, y: 50, width: 44, height: 44))
view.addSubview(addButton)
// add target and action
addButton.addTarget(self, action: #selector(addButtonTapped(_:)), forControlEvents: .TouchUpInside)
// change the button state when tapped
@IBAction func addButtonTapped(sender: AddButton) {
sender.added = !sender.added
}
AddButton
provides various customizations which can be done either in code or in Interface Builder.
/// Stroke color for the add sign.
@IBInspectable public var strokeColor: UIColor = UIColor.blackColor()
/// Line width for the add sign / checkmark.
@IBInspectable public var lineWidth: CGFloat = 2.0
/// When set to `true` the button will display a checkmark. When `false` an add sign.
@IBInspectable public var added: Bool = false
/// The additional spacing between the border of the view and the add sign / checkmark.
@IBInspectable public var margin: CGFloat = 8.0
Additionally there is convenience method to add a border to your button.
border(width:color:cornerRadius)
- iOS 8.0
- Swift 2.0
AddButton is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "AddButton"
Created and maintained by @svenbacia
AddButton is available under the MIT license. See the LICENSE file for more info.