您将如何实现下面链接中的模糊/颜色效果(老实说,我不太确定它是什么)?
谢谢!
Best Answer-推荐答案 strong>
好的,我以任何方式发布链接答案的快速版本,类似于您的要求。
你可以像下面那样做,只需创建一个渐变层,你想要的颜色分布在渐变层上,最后将渐变设置为 ImageView ,例如
@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!);
}
尝试放入示例项目,结果将如下所示
关于ios - 您如何创建 iOS 9 音乐应用程序中使用的模糊/颜色效果?,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/37626260/
|