Add convenient method to UIButton to set a background color as an image.

This commit is contained in:
SBiOSoftWhare
2019-11-28 12:42:19 +01:00
parent d5e3171849
commit eb350ec12b
+11
View File
@@ -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)
}
}