Image使わなくてもアイコン表示できる。
Label("Lightning", systemImage: "bolt.fill")
labelStyleでアイコン指定してても非表示にできる。
Label("Lightning", systemImage: "bolt.fill") .labelStyle(.titleOnly)
自分でStyleを作ることもできる。
Style作れるのは便利っぽい。
struct RedBorderedLabelStyle: LabelStyle { func makeBody(configuration: Configuration) -> some View { Label(configuration) .border(Color.red) } }
Label("Lightning", systemImage: "bolt.fill") .labelStyle(RedBorderedLabelStyle())
グループに設定し、一括してStyleを指定できる。
VStack { Label("Rain", systemImage: "cloud.rain") Label("Snow", systemImage: "snow") Label("Sun", systemImage: "sun.max") } .labelStyle(.iconOnly)
Lable最初のブロック内はHStackと同じ扱いっぽい。
UITableViewCellっぽくできそう。
iconブロックでアイコンの部分のカスタマイスができる。
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)) }