Created
August 8, 2016 07:22
-
-
Save zummenix/67adccc1ee893ade8fb27a5a5a790498 to your computer and use it in GitHub Desktop.
Generates an image with radial gradient.
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
private extension UIImage { | |
static func radialGradientImageWithSize(size: CGSize, outerColor: UIColor, innerColor: UIColor) -> UIImage { | |
let colorSpace = CGColorSpaceCreateDeviceRGB() | |
let gradient = CGGradientCreateWithColors(colorSpace, [outerColor.CGColor, innerColor.CGColor], [1.0, 0.0]) | |
let center = CGPoint(x: size.width / 2.0, y: size.height / 2.0) | |
UIGraphicsBeginImageContextWithOptions(size, false, UIScreen.mainScreen().scale) | |
let imageContext = UIGraphicsGetCurrentContext() | |
CGContextDrawRadialGradient(imageContext, gradient, center, 0.0, center, size.width / 2.0, CGGradientDrawingOptions.DrawsAfterEndLocation) | |
let image = UIGraphicsGetImageFromCurrentImageContext() | |
UIGraphicsEndImageContext() | |
return image | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment