[英]How do you create the blur/colour effect used in the iOS 9 music app?
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 您可以按照下面的步骤进行操作,只需创建一个具有颜色u的渐变层,然后将其分布在整个渐变层上,最后将渐变设置为图像视图即可,例如
@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 只需尝试放入示例项目中,结果将如下所示
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.