I need overlay UINavigationBar
with UIView
like here
Here's how implemented mine, hope this helps..
override func viewWillAppear(_ animated: Bool) {
let testView = UIView(frame: .zero)
testView.backgroundColor = .black
testView.layer.cornerRadius = 10
testView.translatesAutoresizingMaskIntoConstraints = false
self.navigationController?.navigationBar.addSubview(testView)
NSLayoutConstraint.activate([
testView.widthAnchor
.constraint(equalToConstant: 50),
testView.heightAnchor
.constraint(equalToConstant: 70),
testView.topAnchor
.constraint(equalTo: (self.navigationController?.navigationBar.topAnchor)!),
testView.trailingAnchor
.constraint(equalTo: (self.navigationController?.navigationBar.trailingAnchor)!, constant: -20)
])
self.customView = testView
}
// i dont need to display the overlay in every page
// so i remove it everytime i navigate to a new page
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.customView.removeFromSuperview()
}