CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.
TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Jul 2015 |
SPMSupports SPM | ✗ |
Maintained by Clay Smith.
Swift framework to configure and switch between multiple appearances of a UIButton, courtesy of Talking Bibles International and Clay Smith
This framework adds a TBMultiAppearanceButton
subclass of UIButton
. This new class
allows for switching between multiple appearances of the button, each with its own full
complement of UIButton
core properties. Each appearance may be configured for all
UIControlStates
, including highlight and selected.
The possible appearances are cases of an enum that conforms to TBControlAppearanceType
with a raw type of Int
. This enum can be used to control the appearance of multiple
buttons.
enum PlayerButtonAppearance: Int, TBControlAppearanceType {
case Play = 2
case Pause = 3
}
Buttons must be programmatically created (at least for now), because the new button class is generic. It must be specified with an appearance enum.
let button = TBMultiAppearanceButton<PlayerButtonAppearance>(frame: someFrame)
The properties of the button can now be configured for each of the appearances. Changing a stored property will update the appearance if the specified appearance and state are currently displayed.
button.setTitle("Play", forAppearance: .Play, andState: .Normal)
button.setTitle("Play", forAppearance: .Pause, andState: .Normal)
button.setBackgroundImage(UIImage.imageWithColor(UIColor.blueColor()), forAppearance: .Play, andState: .Normal)
button.setBackgroundImage(UIImage.imageWithColor(UIColor.lightGrayColor()), forAppearance: .Play, andState: .Normal)
The button can receive all the same messages as a UIButton
. But the display properties of
the button will be overwritten by any stored appearance properties whenever the button
changes appearance or state. For this reason, it is advised to change the display
properties of the button only through the provided methods.
// Bad :(
// Will probably be overwritten
self.setTitle("Play", forState: .Normal)
// Good :)
button.setTitle("Play", forAppearance: .Play, andState: .Normal)
Switching between appearances is simple. The button will retain its current state, and any properties configured for the appearance will be changed on the button.
// Select an appearance
button.activateAppearance(.Play)
// Later... select another appearance
button.activateAppearance(.Pause)
This framework does not make any further changes to UIButton
beyond adding on appearance
control. The subclassed button can be used without fear of cross-interaction any where a
built-in button could go.
This project is compatible with Cocoapods and Carthage. (These instructions assume that your chosen method is already installed.)
See License