Toggle

2020-03-28  本文已影响0人  水之飞亦

Creating a Toggle

init(ToggleStyleConfiguration)

Available when Label is ToggleStyleConfiguration.Label.

init(LocalizedStringKey, isOn: Binding<Bool>)

Available when Label is Text.

init<S>(S, isOn: Binding<Bool>)

Available when Label is Text.

init(isOn: Binding<Bool>, label: () -> Label)

Creates an instance that displays state based on isOn.

Styling a Toggle

struct DefaultToggleStyle

struct SwitchToggleStyle

struct CheckboxToggleStyle

protocol ToggleStyle

A specification for the appearance and interaction of a Toggle.

Toggle.init(isOn: $isOn) {
     Button.init("button") {
         print("button")
     }
}
Toggle.init(isOn: $isOn) {
     Text("开启定位")
         .foregroundColor(Color.purple)
}
Toggle.init("允许读取通讯录", isOn: $isOn)
     .toggleStyle(DefaultToggleStyle())
上一篇下一篇

猜你喜欢

热点阅读