mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-20 16:42:44 +02:00
Add convenient method to UIButton to set a background color as an image.
This commit is contained in:
@@ -29,4 +29,15 @@ extension UIButton {
|
||||
titleLabel.numberOfLines = 0
|
||||
titleLabel.textAlignment = textAlignment
|
||||
}
|
||||
|
||||
/// Set background color as an image.
|
||||
/// Useful to automatically adjust highlighted background if `adjustsImageWhenHighlighted` property is set to true or disabled background when `adjustsImageWhenDisabled`is set to true.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - color: The background color to set as an image.
|
||||
/// - state: The control state for wich to apply this color.
|
||||
func vc_setBackgroundColor(_ color: UIColor, for state: UIControl.State) {
|
||||
let image = UIImage.vc_image(from: color)
|
||||
self.setBackgroundImage(image, for: state)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user