[SUI] 表单 (Form)
发布: (2026年1月31日 GMT+8 05:42)
1 min read
原文: Dev.to
Source: Dev.to
Form
Form 是一个用于分组控件的容器,主要用于某些功能的配置。
它以 grouped 样式的 List 展示控件,并在四周留有填充。
与 List 组件类似,Form 也可以使用 Section 将内容分成多个部分。
示例
enum NotifyMeAboutType {
case directMessages, mentions, anything
}
enum ProfileImageSize {
case large, medium, small
}
struct ContentView: View {
@State private var notifyMeAbout: NotifyMeAboutType = .anything
@State private var playNotificationSounds = false
@State private var sendReadReceipts = false
@State private var profileImageSize: ProfileImageSize = .small
var body: some View {
NavigationView {
Form {
Section(header: Text("Notifications"),
footer: Text("¿Qué quieres que te notifique?")) {
Picker("Notify Me About", selection: $notifyMeAbout) {
Text("Direct Messages").tag(NotifyMeAboutType.directMessages)
Text("Mentions").tag(NotifyMeAboutType.mentions)
Text("Anything").tag(NotifyMeAboutType.anything)
}
Toggle("Play notification sounds", isOn: $playNotificationSounds)
Toggle("Send read receipts", isOn: $sendReadReceipts)
}
Section(header: Text("User Profiles")) {
Picker("Profile Image Size", selection: $profileImageSize) {
Text("Large").tag(ProfileImageSize.large)
Text("Medium").tag(ProfileImageSize.medium)
Text("Small").tag(ProfileImageSize.small)
}
Button("Clear Image Cache") {}
}
}
}
}
}