UIButton set title image tint color for normal and selected not working

Problem: I had a button with image and title with one color for normal state and other color for selected state. But unfortunately it was not working as expected Solution: extension UIButton { func setBackgroundColor ( color : UIColor , forState : UIControlState) { UIGraphicsBeginImageContext ( CGSize ( width : 1 , height : 1 )) CGContextSetFillColorWithColor( UIGraphicsGetCurrentContext (), color. CGColor ) CGContextFillRect( UIGraphicsGetCurrentContext (), CGRect ( x : 0 , y : 0 , width : 1 , height : 1 )) let colorImg = UIGraphicsGetImageFromCurrentImageContext () UIGraphicsEndImageContext () self .setBackgroundImage(colorImg, forState: forState) } } I...