加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Swift:圆形UIButton,背景模糊

发布时间:2020-12-14 04:44:08 所属栏目:百科 来源:网络整理
导读:我想制作一个圆形的UIButton但是具有光线模糊效果和活力,因为它的背景 到目前为止,我已经有了一个圆形的UIButton,但我在网上找到的代码(我是iOS新手,我不是很了解模糊等是如何工作的)添加模糊只是将它作为整个按钮的框架,基本上使按钮再次显示为方形. 我也尝
我想制作一个圆形的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)

解决方法

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

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

请享用!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读