作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
最佳答案
好吧,无论如何我都会发布链接答案的快速版本,类似于您的要求。
你可以像下面那样做,只需创建一个渐变层,你想在渐变层上传播颜色,最后将渐变设置为 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/
我是一名优秀的程序员,十分优秀!