如何将自定义字体和图像添加到我的选择器中?
我的应用程序中有一个选择器,显示当前选择选项作为其标签。但是,我似乎无法弄清楚如何更改选择器为其标签所使用的字体以及显示所有选择器选项。我还想将一个图标放在选择器按钮的一部分的文本的前面,但不会像文本那样更改,以便用户可以单击文本和图标,以供选择器出现。
这是我为选择器使用的代码:
var fylker = ["Norge", "Akershus", "Agder", "Buskerud", "Finnmark", "Innlandet", "Møre og Romsdal", "Nordland", "Oslo", "Østfold", "Rogaland", "Troms", "Trøndelag", "Vestfold og Telemark", "Vestland"]
Picker("Fylke", selection: $selectedFylke) {
ForEach(fylker, id: \.self) {
Text($0)
}
}
我已经尝试了类似的事情:
Picker("Fylke", selection: $selectedFylke) {
ForEach(fylker, id: \.self) {
Text($0).font(.custom("Custom-Bold", size: 34))
}
}
没有
Picker("Fylke", selection: $selectedFylke) {
ForEach(fylker, id: \.self) {
HStack {
Image(systemName: "chevron.forward.circle")
Text($0)
}
}
}
任何
想法? 谢谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试此方法设置
picker
的字体:这确实不是与PickerStyle一起工作:
自动>自动
,菜单
菜单>和分割
try this approach to set the font used by the
Picker
:This does not work with pickerStyle:
automatic
,menu
andsegmented
据我了解,我认为您可以尝试使用字体修改器添加您的自定义字体并在HSTACK中添加图像,以便它们彼此旁边,例如
from what i understand i think you could try to use a font modifier to add your custom font and add image inside HStack so they are beside each other like that
另外,如果您是要添加选择器旁边的图像,那么它们似乎是按钮拾取器,您可以做
。
also if you mean to add the image beside the picker so they seemed as a button picker you can do that