Label Styles
Last updated
Was this helpful?
Last updated
Was this helpful?
SwiftUI โฉ Controls โฉ Label โฉ
ๅ
งๅปบๆจฃๅผ็ฑ labelStyle(_:)
่จญๅฎ๏ผ
automatic
(้ ่จญ) : ๆ นๆๆๅจ็ไฝ็ฝฎ๏ผ่ชๅๆฑบๅฎ่ฆ็จๅชไธ็จฎใ
titleOnly
: ๅชๆๆๅญใ
iconOnly
: ๅชๆๅ็คบใ
titleAndIcon
: ๆๅญใๅ็คบ้ฝๆใ
๐ ๅ่๏ผ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") }
}
}
}