๐ SwiftUI โฉ Label
struct ContentView: View {
@State private var isOn = true
var body: some View {
Toggle(isOn: $isOn){
Label("Hello", systemImage: "person")
// ๐ .redBorder
.labelStyle(.redBorder)
}
}
}
// โญ๏ธ custom label style
struct RedBorderedLabelStyle: LabelStyle {
// โญ๏ธ protocol's only requirement
func makeBody(configuration: Configuration) -> some View {
Label(configuration)
.padding(4)
.border(Color.red)
}
}
// ๐ .redBorder
// โญโโโโโโโโโ โญ๏ธ important โโโโโโโโโโโฎ
extension LabelStyle where Self == RedBorderedLabelStyle {
// extension supports "computed properties" (no "stored properties")
public static var redBorder: RedBorderedLabelStyle {
RedBorderedLabelStyle()
}
}