I'm attempting to use an untappable UIBarButtonItem in a NavBar that would display a glyph and use CALayer to show a background shadow. I have noticed that the item displays correctly at startup, however as soon as I push a new viewController the UIBarButtonItem clips. Do any of you know of a way to prevent the clipping that occurs after a push?
thanks, in advance!
At app launch
After push and pop
class ViewController: UIViewController {
var showBack: Bool
init(showBack: Bool = false) {
self.showBack = showBack
super.init(nibName: nil, bundle: nil)
}
required init?(coder: NSCoder) {
self.showBack = false
super.init(coder: coder)
}
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.rightBarButtonItem = barButton
if !showBack {
navigationItem.leftBarButtonItem = barButton
}
}
var barButton: UIBarButtonItem {
let config = UIImage.SymbolConfiguration(pointSize: 30)
let view: UIImageView = .init(image: UIImage(systemName: "multiply.circle", withConfiguration: config))
view.layer.shadowColor = UIColor.black.cgColor
view.layer.shadowRadius = 10
view.layer.shadowOffset = .zero
view.layer.shadowOpacity = 1.0
view.layer.masksToBounds = false
return .init(customView: view)
}
@IBAction func navPush(sender: UIButton) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "vc") as! ViewController
vc.showBack = true
self.navigationController?.pushViewController(vc, animated: true)
}
}