I am making an attempt so as to add Shadow to the Border of the UIButton, however it isn’t working. Shadow ought to as seen in picture, however precise requirement is like UIButton will probably be in clear background, and shadow round border. So how can I obtain it?
class GlowButton: UIButton {
non-public let borderGlowLayer = CAShapeLayer()
override init(body: CGRect) {
tremendous.init(body: body)
setup()
}
required init?(coder: NSCoder) {
tremendous.init(coder: coder)
setup()
}
non-public func setup() {
backgroundColor = .clear
layer.masksToBounds = false
clipsToBounds = false
borderGlowLayer.fillColor = UIColor.clear.cgColor
borderGlowLayer.strokeColor = UIColor.clear.cgColor
borderGlowLayer.lineWidth = 2.5
borderGlowLayer.shadowOffset = .zero
borderGlowLayer.shadowRadius = 0
borderGlowLayer.shadowOpacity = 0
borderGlowLayer.masksToBounds = false
layer.addSublayer(borderGlowLayer)
}
override func layoutSubviews() {
tremendous.layoutSubviews()
layer.masksToBounds = false
clipsToBounds = false
borderGlowLayer.body = bounds
borderGlowLayer.path = UIBezierPath(roundedRect: bounds, cornerRadius: 20).cgPath
}
override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
tremendous.didUpdateFocus(in: context, with: coordinator)
coordinator.addCoordinatedAnimations {
if self.isFocused {
self.borderGlowLayer.strokeColor = Colours.focused_border.cgColor
self.borderGlowLayer.shadowColor = Colours.focused_border.cgColor
self.borderGlowLayer.shadowRadius = 12
self.borderGlowLayer.shadowOpacity = 1.0
} else {
self.borderGlowLayer.strokeColor = UIColor.clear.cgColor
self.borderGlowLayer.shadowOpacity = 0.0
self.borderGlowLayer.shadowRadius = 0
}
}
}
}


