๐ ๅ่๏ผSarun โฉ SwiftUI Label: A standard way to label user interface items
struct ContentView: View {
// label
let favLabel = Label("Favorites", systemImage: "heart")
var body: some View {
TabView {
NavigationView {
VStack {
// โญ standalone label: title & icon
favLabel
// โญ button: title & icon (with accent color)
Button {} label: {
favLabel
.padding(.horizontal, 12)
.padding(.vertical, 6)
.background(Color.pink)
.cornerRadius(12)
}
// โญ toggle: title & icon
Toggle(isOn: .constant(true)) { favLabel }
// โญ slider: no label
Slider(value: .constant(5), in: 0...10) { favLabel }
}
.padding()
.toolbar {
// โญ toolbar item: icon only
ToolbarItem(placement: .primaryAction) {
Button { } label: { favLabel }
}
}
}.tabItem {
// โญ tab item: title & icon (filled with accent color)
// rendered vertically when in portrait orientation
favLabel
}
VStack {
Text("Hello World")
}.tabItem { Label("Hello", systemImage: "folder") }
}
}
}