带有动态图像的 SwiftUI 标签
SwiftUI Label with dynamic image
可以在标签中使用动态图像吗?
类似于:
Label("SP98", uiImage: myFunctionToReturnImageFromText("test"))
在这种情况下使用:
Menu {
if fuelTypeisAvailable(fuelType: "Diesel") {
Button {
updateStuff()
Haptics.shared.play(.light)
preferredFuelType = "Diesel"
} label: {
Label("Diesel", systemImage: "fuelpump.circle")
}
}
谢谢
试试这个
struct ImageLabel: View {
let title: String
let image: Image
public init(_ title: String, uiImage: UIImage) {
self.title = title
self.image = Image(uiImage: uiImage)
}
public init(_ title: String, image: Image) {
self.title = title
self.image = image
}
var body: some View {
Text(title)
image
}
}
我认为您要使用的初始化程序是:
Label {
Text("SP98")
} icon: {
Image(uiImage: myFunctionToReturnImageFromText("test"))
}
可以在标签中使用动态图像吗?
类似于:
Label("SP98", uiImage: myFunctionToReturnImageFromText("test"))
在这种情况下使用:
Menu {
if fuelTypeisAvailable(fuelType: "Diesel") {
Button {
updateStuff()
Haptics.shared.play(.light)
preferredFuelType = "Diesel"
} label: {
Label("Diesel", systemImage: "fuelpump.circle")
}
}
谢谢
试试这个
struct ImageLabel: View {
let title: String
let image: Image
public init(_ title: String, uiImage: UIImage) {
self.title = title
self.image = Image(uiImage: uiImage)
}
public init(_ title: String, image: Image) {
self.title = title
self.image = image
}
var body: some View {
Text(title)
image
}
}
我认为您要使用的初始化程序是:
Label {
Text("SP98")
} icon: {
Image(uiImage: myFunctionToReturnImageFromText("test"))
}