Swift: round UIButton with blur background

I want to make a round UIButton, but with a slight blurry effect with brightness, since it is a background

So far I have a rounded UIButton, but the code I found on the network (I am new to iOS development, so I don’t understand how blur works, etc.) to add blur, just puts it as a whole, which makes the button again square.

I also tried adding a view, then UIButton, and then a blur effect, and applied the cornerRadius code to that view, but it also didn't work.

Here is what I tried:

    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)
+4
source share
1 answer

, subview:

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

!:)

+5

Source: https://habr.com/ru/post/1622531/


All Articles