Skip to content

serge-nanaev/SwiftyButton

 
 

Repository files navigation

SwiftyButton

Simple and customizable button in Swift.

Installation

pod 'SwiftyButton'

Usage

Flat Button

let button = SwiftyButton()
button.buttonColor      = .cyanColor()
button.highlightedColor = .blueColor()
button.shadowHeight     = 0
button.cornerRadius     = 5

Pressable Button

let button = SwiftyButton()
button.buttonColor  = .cyanColor()
button.shadowColor  = .blueColor()
button.shadowHeight = 5
button.cornerRadius = 5

All Properties

Here is a list of all the properties of SwiftyButton that you can modify. Those are all editable directly from Interface Builder. See SwiftyButtonDefaults to set defaults for those properties.

button.buttonColor         = UIColor.cyanColor()
button.highlightedColor    = UIColor.cyanColor()
button.shadowColor         = UIColor.blueColor()
button.disabledButtonColor = UIColor.grayColor()
button.disabledShadowColor = UIColor.darkGrayColor()
button.shadowHeight        = 10
button.cornerRadius        = 8
button.buttonPressDepth    = 0.5 // In percentage of shadowHeight

Interface Builder (Storyboard/XIB)

Add a UIButton as usual, modify the underlying class to SwiftyButton, and make sure that the button type is set to Custom:

Defaults

You can set defaults that will be applied for any new instance of SwiftyButton by modifying the SwiftyButtonDefaults structure:

SwiftyButtonDefaults.buttonColor = UIColor.cyanColor()
SwiftyButtonDefaults.cornerRadius = 8
...

Custom Content

Use SwiftyCustomContentButton to add custom content in a Swifty Button.

This is a subclass of SwiftyButton that exposes a content view that moves when the button state changes. All you have to do is add your views inside button.customContentView and setup layout constraints relative to this view.

Install

pod `SwiftyButton/CustomContent`

Usage

Here is how you would create a button similar to the one above (here we used PureLayout for constraints):

let button = SwiftyCustomContentButton()

let indicator = UIActivityIndicatorView(activityIndicatorStyle: .White)
button.customContentView.addSubview(indicator)
indicator.autoPinEdgesToSuperviewEdgesWithInsets(UIEdgeInsets(top: 10, left: 15, bottom: 10, right: 0), excludingEdge: .Right)
indicator.startAnimating()

let label = UILabel()
button.customContentView.addSubview(label)
label.autoPinEdgesToSuperviewEdgesWithInsets(UIEdgeInsets(top: 10, left: 0, bottom: 10, right: 10), excludingEdge: .Left)
label.autoPinEdge(.Left, toEdge: .Right, ofView: indicator, withOffset: 10)
label.text = "Loading..."
label.textColor = UIColor.whiteColor()

More examples

Look at the Examples folder to see more button examples.

License

This project is copyrighted under the MIT license. Complete license can be found here: https://github.com/TakeScoop/SwiftyButton/blob/master/LICENSE

Credits

About

Simple and customizable button in Swift

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 85.4%
  • Ruby 9.6%
  • Objective-C 5.0%