SwiftUI之常见UI

2019-11-01 16:16:06 浏览数 (1)

struct Settings:View {

@State var toogleOn:Bool = false

@State var number = 1

@State var selection = 1

var body: some View{

NavigationView{

Form{

Toggle(isOn: $toogleOn) {

if toogleOn{

Text("Hi, I am on")

}else{

Text("Hi, I am off")

}

}

Stepper(value: $number, in: 1 ... 7) {

Text("(number) of weak" )

}

Picker(selection: $selection, label: Text("Picker")) {

Text("Pick 1").tag(1)

Text("Pick2").tag(2)

}

Button(action: {self.toogleOn.toggle()}) {

Text("submit")

}

.alert(isPresented: $toogleOn) {

Alert(title: Text("Thanks"), message: Text("I am learn swiftUI"))

}

}.navigationBarTitle("Settings")

}

}

}

struct Settings_Previews: PreviewProvider {

static var previews: some View {

Settings()

}

}

0 人点赞