ok any way i am posting the swift version of the linked answer, similar to your requirement.
u can do like below, just create a gradient layer with the color's u want to spread across the gradient layer finally set the gradient later to image view, for example
@IBOutlet weak var aImageView: UIImageView!
var theColor: UIColor?
var gradientLayer:CAGradientLayer?
override func viewDidLoad()
{
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.theColor = UIColor(colorLiteralRed: 146.0/255.0, green: 146.0/255.0, blue: 146.0/255.0, alpha: 1)
self.gradientLayer = CAGradientLayer()
self.gradientLayer?.frame = self.aImageView.frame
let array: [AnyObject] = [(theColor?.colorWithAlphaComponent(0.1))!.CGColor,
(theColor?.colorWithAlphaComponent(0.12))!.CGColor,(theColor?.colorWithAlphaComponent(0.13))!.CGColor,
(theColor?.colorWithAlphaComponent(0.74))!.CGColor,
(theColor?.colorWithAlphaComponent(0.82))!.CGColor,
(theColor?.colorWithAlphaComponent(1.0))!.CGColor]
gradientLayer?.colors = array;
aImageView.layer .addSublayer(gradientLayer!);
}
just try put in sample project, the result will be like below
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.