12:SwiftUI-Toggle开关
正文
// // TogglePage.swift // SwiftUIDeom // // Created by zhoukang03 on 2023/3/28. // import SwiftUI struct TogglePage: View { @State var isOn = false var body: some View { VStack { Toggle(isOn: $isOn) { Text("State:\(self.isOn ? "开" : "关")") }.padding(20) Spacer() // 棉花糖,填充,空间均分 }.navigationTitle("开关") } } #if DEBUG struct TogglePage_Previews: PreviewProvider { static var previews: some View { TogglePage() } } #endif
示例图