here i can attached screenshots which i faced as an issue when scrolling at time i want to hide that more button or put that button into navigation bar as 2nd button but it’s override to 1st one.
i set button into did load by calling simply this function.
func setUpNavigationMoreButton() {
let rightButton = UIButton()
let btnFilterImage = #imageLiteral(resourceName: "DotsThreeOutline")
rightButton.setImage(btnFilterImage, for: .normal)
rightButton.setTitleColor(.purple, for: .normal)
rightButton.addTarget(self, action: #selector(filterClick), for: .touchUpInside)
navigationController?.navigationBar.addSubview(rightButton)
rightButton.tag = 1
rightButton.frame = CGRect(x: self.view.frame.width, y: 0, width: 30, height: 30)
let targetView = self.navigationController?.navigationBar
let trailingContraint = NSLayoutConstraint(item: rightButton, attribute:
.trailingMargin, relatedBy: .equal, toItem: targetView,
attribute: .trailingMargin, multiplier: 1.0, constant: -16)
let bottomConstraint = NSLayoutConstraint(item: rightButton, attribute: .bottom, relatedBy: .equal,
toItem: targetView, attribute: .bottom, multiplier: 1.0, constant: -6)
rightButton.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([trailingContraint, bottomConstraint])
}
2
Answers
You have to use UIBarButtonItem instead of a UIButton.
If you have multiple buttons
If you need to hide/unhide the more button when the Large title changes.