Gradient Image with Colors iOS
1 min readOct 5, 2020
Creating Gradient UIImage with colors in CGRect
Swift:
extension UIImage {
static func gradientImageWithBounds(bounds: CGRect, colors: [CGColor]) -> UIImage {let gradientLayer = CAGradientLayer()
gradientLayer.frame = bounds
gradientLayer.colors = colorsUIGraphicsBeginImageContext(gradientLayer.bounds.size)
gradientLayer.render(in: UIGraphicsGetCurrentContext()!)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()return image!
}
}