调用图像时出现错误:
'(String)->图像'不能转换为'(String,Bundle?)->图像'\
此错误显示在Image(specie.imageName)行
这是整个页面代码。
import SwiftUI
struct ForefootView : View {
@State var iconOpacity: Double = 0.5
let specie: Species
var body: some View {
NavigationView {
ZStack () {
Image("Busanga")
.resizable()
VStack (spacing: 10) {
Image(specie.imageName)
.resizable()
.aspectRatio(contentMode: .fit)
.cornerRadius(8)
.padding(15)
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity)
ZStack() {
Image(specie.trackSizerImage)
.resizable()
.aspectRatio(contentMode: .fit)
.opacity(iconOpacity)
Image(specie.frontTrackImage)
.resizable()
.aspectRatio(contentMode: .fit)
}
HStack {
Image(specie.trackSizerImage)
.resizable()
.frame(width: 40, height: 40, alignment: .topLeading)
.opacity(0.2)
Slider(value: $iconOpacity, from: 0.0, through: 1.0)
Image(specie.trackSizerImage)
.resizable()
.frame(width: 40, height: 40, alignment: .topTrailing)
}
.padding(20)
}
}
.navigationBarTitle(Text((specie.fullName) + " " + "FOREFOOT".localized), displayMode: .inline)
.navigationBarItems(trailing: NavigationLink(destination: NotesView(species: specie)) {
Text("Notes").color(.white)
.font(.custom("Marker Felt", size: 15))
.shadow(color:.black, radius:1, x:1, y:1)
})
}
}
}
#if DEBUG
struct ForefootView_Previews : PreviewProvider {
static var previews: some View {
ForefootView(specie: speciesData[0])
}
}
#endif
图像名称Image(specie.imageName)在另一页上使用,很好,因此显然欧元在其他位置。帮助指出可能的关注领域。
答案 0 :(得分:0)
我进行了两项更改,在我逐页浏览所有内容后,错误似乎消失了。
Text("Notes").color(.white)
更改为:
Text("Notes").foregroundColor(Color.white)
和
Slider(value: $iconOpacity, from: 0.0, through: 1.0)
更改为:
Slider(value: $iconOpacity, in:0...1.0)