【问题标题】:How to give color to blurrview in iOS?如何在 iOS 中为 blurrview 赋予颜色?
【发布时间】:2017-05-01 07:34:04
【问题描述】:

我创建了一个模糊视图并添加到主视图的子视图中。这是我的代码:

let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.light)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.tintColor  = UIColor.green
blurEffectView.tag = 999;
let frame:CGRect = CGRect(x: self.internalView.frame.size.width + self.internalView.frame.origin.x, y: self.drawerView.frame.origin.y, width: self.drawerView.frame.size.width - self.internalView.frame.size.width, height: self.drawerView.frame.size.height)

blurEffectView.frame = frame
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
self.drawerView.insertSubview(blurEffectView, belowSubview: self.btnClose)

现在,我想把它变成深绿色的模糊。

如何使用上面的代码实现这一点?

【问题讨论】:

标签: ios swift xcode uiview uiblureffect


【解决方案1】:

试试这个:Swift 3.0

 override func viewDidLoad() {
    super.viewDidLoad()

    let visualEffectView = UIVisualEffectView.init(effect: UIBlurEffect.init(style: .light))
    visualEffectView.backgroundColor = UIColor.init(red: 0.0, green: 0.5, blue: 0.0, alpha: 0.5)
    visualEffectView.frame = self.view.bounds
    self.view.addSubview(visualEffectView)

}

这行代码应该改变visualEffectView的背景颜色。

visualEffectView.backgroundColor = UIColor.init(red: 0.0, green: 0.5, blue: 0.0, alpha: 0.5)

希望对你有帮助!

【讨论】:

  • 将 alpha 值更改为 0.5
  • @dhiraj 我已经更新了我的答案!试试这个,让我知道它是否有效。谢谢
【解决方案2】:

你可以试试这个并调整alpha值:

blurView.backgroundColor = UIColor.red.withAlphaComponent(0.3)

【讨论】:

    猜你喜欢
    • 2020-10-19
    • 1970-01-01
    • 2019-04-16
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 2015-07-16
    • 1970-01-01
    相关资源
    最近更新 更多