SwiftUI - Using Labels

From PeformIQ Upgrade
Revision as of 08:22, 31 July 2024 by PeterHarding (talk | contribs) (Created page with "=SwiftUI Labels= See - https://developer.apple.com/documentation/swiftui/label <pre> Label("Lightning", systemImage: "bolt.fill") </pre> <pre> Label("Lightning", systemImage: "bolt.fill") .labelStyle(.titleOnly) </pre> Label Styles - .titleOnly, .iconOnly and .titleAndIcon <pre> struct RedBorderedLabelStyle: LabelStyle { func makeBody(configuration: Configuration) -> some View { Label(configuration) .border(Color.red) } } </pre> <pre...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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))
}