如何创建iOS 9音乐应用程序中使用的模糊/颜色效果?

时间:2016-06-04 04:09:47

标签: ios swift

如何在下面的链接中看到模糊/颜色效果(我不太确定它是什么,说实话)?

谢谢!

1 个答案:

答案 0 :(得分:0)

确定无论如何我都会发布链接答案的快速版本,类似于您的要求。

你可以这样做,只需创建一个颜色的渐变图层,你想要在渐变层上展开,最后将渐变设置为图像视图,例如

@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!);
}

只需尝试输入示例项目,结果如下

enter image description here