Created
November 9, 2015 21:51
-
-
Save viccc/01e28adcdee5cf6b9980 to your computer and use it in GitHub Desktop.
Create an empty UIImage of a given size, optionally filled with a given color. Swift.
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
func imageWithPixelSize(size: CGSize, filledWithColor color: UIColor = UIColor.clearColor(), opaque: Bool = false) -> UIImage { | |
return imageWithSize(size, filledWithColor: color, scale: 1.0, opaque: opaque) | |
} | |
func imageWithSize(size: CGSize, filledWithColor color: UIColor = UIColor.clearColor(), scale: CGFloat = 0.0, opaque: Bool = false) -> UIImage { | |
let rect = CGRectMake(0, 0, size.width, size.height) | |
UIGraphicsBeginImageContextWithOptions(size, opaque, scale) | |
color.set() | |
UIRectFill(rect) | |
let image = UIGraphicsGetImageFromCurrentImageContext() | |
UIGraphicsEndImageContext() | |
return image | |
} |
mtavkhelidze
commented
Jul 28, 2019
If you are suggesting there's such a UIImage method provided by Apple, I don't think so...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment