原文链接:https://github.com/fzhlee/SwiftUI-Guide#-%E7%AC%AC10%E8%8A%82navigationitem-
为了丰富应用程序的功能,经常需要在导航栏添加一些功能按钮。本节课演示如何制作这些导航按钮。
示例代码:
struct TrailingButtons : View{
var body: some View {
HStack{
Button(action: {
print("Download the data")
}) {
Image(systemName: "icloud.and.arrow.down.fill")
}
Button(action: {
print("Edit the data")
}) {
Image(systemName: "pencil.tip.crop.circle")
}
}
}
}
struct ContentView : View {
var body: some View {
NavigationView {
Text("SwiftUI's NavigationView")
.navigationBarTitle(Text("SwiftUI"))
.navigationBarItems(leading: Button(action: {
print("Go to index page")
}) {
Text("Index")
}, trailing: TrailingButtons())
}
}
}
网友评论