答案 0 :(得分: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)
答案 1 :(得分:0)
如果要使用Button
在NavigationBar
中添加SwiftUI
,请尝试以下代码。
struct ContentView: View {
var body: some View {
NavigationView {
VStack{
Text("Hello World!!")
}
.navigationBarItems(trailing:
HStack {
Button(action: {
//action
}) {
Image(systemName: "trash")
.frame(width: 25, height: 25, alignment: .center)
.foregroundColor(.black)
}
Spacer().frame(width: 10)
Button(action: {
//action
}) {
Image(systemName: "link")
.frame(width: 25, height: 25, alignment: .center)
.foregroundColor(.black)
}
}
)
}
}
}