我想在我的選擇器中使用一些文本旁邊的影像,但是影像被放大了,我不能用 .resizable .frame 和 ... 來調整它的大小。我該如何解決這個問題?我同時使用 svg 和 png 格式,但它們都不能正常作業。
我使用資產中的影像

struct ContentView: View {
@State var array = ["one", "two", "three", "four"]
@State var selection: String = "one"
var body: some View {
HStack {
Picker("Select",selection: $selection) {
ForEach(array, id: \.self) { item in
HStack {
Text(item)
Image("BTC")
.resizable()
.clipped()
}
}
}
.pickerStyle(.menu)
.padding(.trailing)
}
}
}
uj5u.com熱心網友回復:
您可以Menu為此目的使用:
struct ContentView: View {
@State var array = ["one", "two", "three", "four"]
@State var selection: String = "one"
var body: some View {
Menu(content: {
Picker("Select",selection: $selection) {
ForEach(array, id: \.self) { item in
HStack {
Text(item)
Image("BTC")
}
}
}
}, label: {
Text(selection)
})
}
}
uj5u.com熱心網友回復:
這是默認的選單行為。使用任一 SF 影像,例如
ForEach(array, id: \.self) { item in
Label(item, systemImage: "bitcoinsign.circle")
}

或原始尺寸較小的光柵影像,例如
ForEach(array, id: \.self) { item in
Label(item, image: "bitcoin") // in Assets 24x24
}

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/496558.html
下一篇:Firefox將SVG顯示為黑色
