What is the best way to align right bar button items with left title in UINavigationBar
?
(now I have the icons at the top right corner)
maybe there is a more correct and optimal solution, but it is suitable for me. Do not be alarmed by the syntax, I use SnapKit
lazy private var settingsButton = UIButton().then {
$0.setImage(Image.settings, for: .normal)
}
viewDidAppear(_ animated: Bool)
navigationController?.navigationBar.subviews.forEach { subview in
let stringFromClass = NSStringFromClass(subview.classForCoder)
guard stringFromClass.contains("UINavigationBarLargeTitleView") else { return }
subview.subviews.forEach { label in
guard label is UILabel else { return }
subview.addSubview(settingsButton)
settingsButton.snp.makeConstraints{
$0.top.equalTo(label)
$0.right.equalToSuperview().offset(-14)
$0.height.width.equalTo(35)
}
}
}
UIScrollViewDelegate
and in scrollViewDidScroll
method get ahead of the navigationBar
state and then hide / show the UIBarButtonItem
screenshot
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With