Last active
August 29, 2015 14:23
-
-
Save wasnot/01dd61b7057ac1cbf3a7 to your computer and use it in GitHub Desktop.
[iOS][Swift]Storyboardでボタン背景色の設定がしたい ref: http://qiita.com/wasnot/items/3537d932e9550a5c4c27
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIButton { | |
private func imageWithColor(color: UIColor) -> UIImage { | |
let rect = CGRectMake(0.0, 0.0, 1.0, 1.0) | |
UIGraphicsBeginImageContext(rect.size) | |
let context = UIGraphicsGetCurrentContext() | |
CGContextSetFillColorWithColor(context, color.CGColor) | |
CGContextFillRect(context, rect) | |
let image = UIGraphicsGetImageFromCurrentImageContext() | |
UIGraphicsEndImageContext() | |
return image | |
} | |
func setBackgroundColor(color: UIColor, forUIControlState state: UIControlState) { | |
self.setBackgroundImage(imageWithColor(color), forState: state) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment