diff --git a/Riot/Categories/UIButton.swift b/Riot/Categories/UIButton.swift index 01c1095f4..0e3af78ef 100644 --- a/Riot/Categories/UIButton.swift +++ b/Riot/Categories/UIButton.swift @@ -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) + } }