I am trying to create a custom UIView class that I can change the class for some views in my app. I want the view to be round and have the blur effect. I can get it to work via func that specifically references the outlet name but would like to just change the class of the view so it is reuseable.
import UIKit
class RoundedBlur: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
self.addRoundedBlur()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.addRoundedBlur()
}
func addRoundedBlur() {
let roundedBlurView = UIView()
let blur = UIVisualEffectView(effect: UIBlurEffect(style: UIBlurEffectStyle.light))
blur.frame = roundedBlurView.bounds
blur.layer.cornerRadius = 0.5 * roundedBlurView.bounds.size.width
blur.clipsToBounds = true
blur.autoresizingMask = [.flexibleWidth, .flexibleHeight]
roundedBlurView.insertSubview(blur, at: 0)
}
}