ios - UIButton with rounded rects and custom backgroundImage when highlighted -
The problem is that my button is highlighted when displayed correctly. I should have background image blue, not opaque The code I use is presented below. and method for obtaining an image with a color.
Selfkbtnkleyrkbordavidth = 1.0 Selfkbtnkleyrkboardaersolor = Selfkbtnktintklor? .CGColor self.button.layer.cornerRadius = 5.0 self.button.layer. masksToBounds = true self.button.setTitleColor (UIColor.whiteColor (), forState: UIControlState.Highlighted) self.button.setBackgroundImage (self.imageWithColor (self.button.tintColor!, size: self.button.bounds.size), forState : UIControlState.Highlighted)
function imageWithColor (color: UIColor, size: CGSize) - & gt; UIImage {UIGraphicsBeginImageContextWithOptions (size, really, 1.0) color.setFill () var frame = CGRectMake (0, 0, size.width, size.height) UIRectFill (border) to image = UIGraphicsGetImageFromCurrentImageContext (); UIGraphicsEndImageContext () Return Image; }
Comments
Post a Comment