The gist demonstrates how to add a custom UIControlState
and set image for that state to a custom UIButton
.
Last active
May 26, 2020 11:50
-
-
Save T-Pham/82e8f4fe9676cef4923aa05fff27f6cb to your computer and use it in GitHub Desktop.
Custom UIControlState
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let myButton = MyButton() | |
myButton.setImage(UIImage(named: "ErrorCross"), forState: .Error) | |
myButton.setImage(UIImage(named: "ErrorCross"), forState: [.Error, .Highlighted]) | |
myButton.setImage(UIImage(named: "ErrorCross"), forState: [.Error, .Selected]) | |
myButton.setImage(UIImage(named: "ErrorCross"), forState: [.Error, .Selected, .Highlighted]) | |
myButton.error = true |
@pavankataria 1 << 16
until 1 << 23
are reserved for custom states, so you can have 9 different states
and how would you define the
1 << 16
part if you wanted multiple custom states?
You could do this:
extension UIControl.State {
static let customState = UIControl.State(rawValue: 1 << 16)
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
and how would you define the
1 << 16
part if you wanted multiple custom states?