我想制作一个带有轻微模糊效果和生动感背景的圆形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)