iOS:如何在导航栏中放置与NavigationBar标题平行的按钮?

问题描述 投票:0回答:1

我想在导航栏标题的同一级别上放置一个按钮。

像下面的图像。

也需要swiftui中的解决方案。

like this

ios swift xcode swiftui uinavigationbar
1个回答
0
投票

您是否尝试过放置UIBarButton项目?您可以将其放在情节提要中的导航栏上。您可以像下面这样以编程方式创建它,并将其设置为导航栏的导航项。

let btn1 = UIButton(type: .custom)
btn1.setImage(UIImage(named: "imagename"), for: .normal)
btn1.addTarget(self, action: #selector(methodname), for: .touchUpInside)
let item1 = UIBarButtonItem(customView: btn1)
self.navigationItem.setRightBarButtonItems([item1], animated: true)
© www.soinside.com 2019 - 2024. All rights reserved.