本文价值与收获
看完本文后,您将能够作出下面的界面
看完本文您将掌握的技能
- 掌握Picker基础使用
- 掌握Form基础
- Picker和Form联动
代码
import SwiftUI
struct PickerForm: View {
@State var countryIndex = 0
@State var countries = ["苹果","西瓜","芒果","猕猴桃"]
var body: some View {
NavigationView{
Form{
Section {
Picker(selection: self.$countryIndex, label: Text("水果")) {
ForEach(0 ..< self.countries.count) {
Text(self.countries[$0]).tag($0)
}
}
}
}
}
}
}
struct PickerForm_Previews: PreviewProvider {
static var previews: some View {
PickerForm()
}
}
推荐文章
- SwiftUI一篇文章全面掌握Picker,解决数据选择(教程和源码)
- SwiftUI实战之用Picker做个优雅的菜单
- SwiftUI实战之如何获取Picker数据修改事件
- SwiftUI实战之用Picker做个优雅的菜单
- SwiftUI基础之Picker带图片和图标效果(教程和源码)
- SwiftUI实战之Picker弹出式显示进行背景模糊(教程含源码)
技术交流
QQ:3365059189
SwiftUI技术交流QQ群:518696470