【发布时间】:2024-01-23 20:13:02
【问题描述】:
我的应用程序中有一个设置视图,它提供了一个使用此代码从选择器中选择值的选项:
var body: some View {
NavigationView {
Form {
Section(header: Text("Widget Settings")) {
Picker(selection: $chosenMediumType, label: Text("Medium Widget"), content: {
VStack {
Image(uiImage: UIImage(systemName: "sun.min")!).resizable().frame(width: 20, height: 20, alignment: .center)
Text("Sun")
}.tag(0)
VStack {
Image(uiImage: UIImage(systemName: "sunset")!).resizable().frame(width: 20, height: 20, alignment: .center)
Text("Sunset")
}.tag(1)
VStack {
Image(uiImage: UIImage(systemName: "moon")!).resizable().frame(width: 20, height: 20, alignment: .center)
Text("Moon")
}.tag(2)
})
.onChange(of: chosenMediumType) { print("Selected tag: \($0)") }
}
}
.navigationBarTitle("Settings")
}
}
当我单击选择器行时,它会打开选择器页面,我可以看到每一行都有图像和文本,但是在设置中,它会使行变大,如图所示:
是否可以只在设置页面中使用文本,在选择器视图中使用图像+文本?
【问题讨论】:
-
现在,没有。已经有类似的问题 - Picker 使用相同的单元格在两种模式下进行绘制。