【问题标题】:Swift: Round UIButton with Blur backgroundSwift:具有模糊背景的圆形 UIButton
【发布时间】:2016-01-02 17:28:26
【问题描述】:

我想做一个圆形的 UIButton,但它的背景是带有活力的光线模糊效果

到目前为止,我有一个圆形的 UIButton,但是我在网上找到的代码(我是 iOS 开发新手,所以不太了解模糊等如何工作)添加模糊只是把它作为整个按钮的框架,本质上使按钮再次显示为方形。

我也尝试过添加一个视图,然后是 UIButton,然后是模糊效果,并将cornerRadius 代码应用于该视图,但它也不起作用。

这是我尝试过的:

    shortcutButton.layer.cornerRadius = 0.5 * shortcutButton.bounds.size.width // add the round corners in proportion to the button size

    let blur = UIVisualEffectView(effect: UIBlurEffect(style:
        UIBlurEffectStyle.Light))
    blur.frame = shortcutButton.bounds
    blur.userInteractionEnabled = false //This allows touches to forward to the button.
    shortcutButton.insertSubview(blur, atIndex: 0)

【问题讨论】:

    标签: swift uibutton swift2 cornerradius uiblureffect


    【解决方案1】:

    在添加子视图之前,将以下两行代码添加到您的项目中:

    blur.layer.cornerRadius = 0.5 * shortcutButton.bounds.size.width
    blur.clipsToBounds = true
    

    享受吧! :)

    【讨论】:

    • 太棒了!谢谢你的帮助。我想我现在明白了 :) 让 Blur “充满活力”怎么样?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-19
    • 2018-11-14
    • 1970-01-01
    • 1970-01-01
    • 2011-12-30
    • 2019-11-27
    • 1970-01-01
    相关资源
    最近更新 更多