gpt4 book ai didi

Swift:带有模糊背景的圆形 UIButton

转载 作者:搜寻专家 更新时间:2023-10-30 22:30:54 26 4
gpt4 key购买 nike

我想制作一个圆形的 UIButton,但具有光模糊效果,背景充满活力

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

我还尝试添加一个 View ,然后是 UIButton,然后是模糊效果,并将 cornerRadius 代码应用到该 View ,但它也没有用。

这是我尝试过的:

    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)

最佳答案

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

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

尽情享受吧! :)

关于Swift:带有模糊背景的圆形 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34568625/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com