Button, 觸發(fā)時執(zhí)行操作的控件.
Button( action: {
// did tap
},
label: { Text("Click Me") }
)
如果你的 Button 的標(biāo)簽只是 Text 你可以用初始化 這個更簡單的聲明些膨。
Button("Click Me") {
// did tap
}
截屏2023-06-13 23.09.36.png
你可以用這個按鈕變得有點漂亮
Button(action: {
}, label: {
Image(systemName: "clock")
Text("Click Me")
Text("Subtitle")
})
.foregroundColor(Color.white)
.padding()
.background(Color.blue)
.cornerRadius(5)
截屏2023-06-13 23.13.11.png
Link, 創(chuàng)建一個鏈接樣式的 按鈕, 它將在關(guān)聯(lián)的應(yīng)用程序(如果可能)怕膛,否則在用戶的默認(rèn)網(wǎng)絡(luò)瀏覽器打開剖膳。
Link("View Our", destination: URL(string: "https://www.baidu.com")!)
截屏2023-06-13 23.23.14.png
NavigationLink, 按下時觸發(fā)導(dǎo)航演示的按鈕系吭。 可替換 pushViewController
NavigationView
{
NavigationLink(destination:
Text("Detail")
.navigationBarTitle(Text("Detail"))
) {
Text("Push")
}.navigationBarTitle(Text("Master"))
}
截屏2023-06-13 23.25.48.png
截屏2023-06-13 23.25.41.png
在 List 中的 NavigationLink 來測試此功能啊易。
NavigationView {
List {
NavigationLink(destination: Text("Detail")) {
Text("Push")
}.navigationBarTitle(Text("Master"))
}
}
截屏2023-06-13 23.29.54.png
如果你的 NavigationLink 的標(biāo)簽只有 Text 你可以 使用這個更簡單的聲明進(jìn)行初始化欠橘。 ???
NavigationLink("Detail", destination: Text("Detail").navigationBarTitle(Text("Detail")))
ToolbarItem, 表示可以放置在工具欄或?qū)Ш綑谥械捻椖康哪P汀?這代表了 UINavigationItem 中的大多數(shù)屬性
添加titleView涛目。
NavigationView {
Text("SwiftUI").padding()
.toolbar {
ToolbarItem(placement: .principal) {
VStack {
Text("Title")
Button("Clickable Subtitle") { print("principle") }
}
}
}
}
截屏2023-06-14 21.49.32.png
添加 LeftBarButtonItem 或 LeftBarButtonItems
NavigationView {
Text("SwiftUI").padding()
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button {
} label: {
Image(systemName: "square.and.pencil")
}
}
}
}
截屏2023-06-14 21.54.11.png
添加 rightBarButtonItem 或 rightBarButtonItems。
NavigationView {
Text("SwiftUI").padding()
.toolbar {
ToolbarItem(placement: .primaryAction) {
Button {
} label: {
Image(systemName: "square.and.pencil")
}
}
ToolbarItem(placement: .navigationBarTrailing) {
Button {
} label: {
Image(systemName: "square.and.pencil")
}
}
}
}
截屏2023-06-14 21.55.07.png