SwiftUI - Using Labels

From PeformIQ Upgrade
Jump to navigation Jump to search

SwiftUI Labels

See - https://developer.apple.com/documentation/swiftui/label

Label("Lightning", systemImage: "bolt.fill")
Label("Lightning", systemImage: "bolt.fill")
    .labelStyle(.titleOnly)

Label Styles - .titleOnly, .iconOnly and .titleAndIcon

struct RedBorderedLabelStyle: LabelStyle {
    func makeBody(configuration: Configuration) -> some View {
        Label(configuration)
            .border(Color.red)
    }
}
VStack {
    Label("Rain", systemImage: "cloud.rain")
    Label("Snow", systemImage: "snow")
    Label("Sun", systemImage: "sun.max")
}
.labelStyle(.iconOnly)
Label {
    Text(person.fullName)
        .font(.body)
        .foregroundColor(.primary)
    Text(person.title)
        .font(.subheadline)
        .foregroundColor(.secondary)
} icon: {
    Circle()
        .fill(person.profileColor)
        .frame(width: 44, height: 44, alignment: .center)
        .overlay(Text(person.initials))
}