๐ฆLabel
Last updated
Last updated
struct ContentView: View {
// view body
var body: some View {
VStack {
favLabel
bondLabel
weatherLabels
}
}
// favorites label
var favLabel: some View {
Label {
Text("Favorites")
.bold()
.foregroundColor(.green) // โญ๏ธ title color
} icon: {
Image(systemName: "heart")
.symbolVariant(.fill)
.foregroundColor(.pink) // โญ๏ธ icon color
}
}
// james bond label
var bondLabel: some View {
Label {
// โญ๏ธ multiple texts
Text("James Bond")
.font(.body)
.foregroundColor(.primary)
Text("Mr.")
.font(.subheadline)
.foregroundColor(.secondary)
} icon: {
// โญ๏ธ custom icon
Circle()
.fill(Color.orange)
.frame(width: 44, height: 44, alignment: .center)
.overlay(Text("JB"))
}
}
var weatherLabels: some View {
HStack {
Label("Rain", systemImage: "cloud.rain")
.foregroundColor(.cyan)
Label("Snow", systemImage: "snow")
Label("Sun", systemImage: "sun.max")
.foregroundColor(.yellow)
}
.labelStyle(.iconOnly) // โญ๏ธ icon only
}
}
struct Label<Title: View, Icon: View>
FIVE STARS โฉ SwiftUI's Label - with custom LabelStyle โญ๏ธ
SwiftUI โฉ Views and Controls โฉ Label โฉ
LabelStyle (protocol)
uses SF Symbols.
used by TabView as tab labels.