我正在尝试将PresentationButton
添加到包含一些Text
和Image
的查看卡视图中。代码如下:
PresentationButton(destination: ProfileHost()) {
CardView()
}
这是我的cardView实现:
struct CardView : View {
@State var isCover = false
var cardFrame: (Length, Length) = (246.0, 391)
var fillColor = Color(red: 69/255, green: 60/255, blue: 201/255, opacity: 0.7)
var body: some View {
ZStack {
Image("image_large") // This is the image that disappears
.resizable()
CoverView(fillColor: fillColor)
.opacity(isCover ? 1:0)
}
.frame(width: cardFrame.0, height: cardFrame.1)
.cornerRadius(10)
}
}
一旦我运行预览,CardView就会变成蓝色,图像消失了。所有文字都不受影响。我认为这与我迅速切换到Color.clear
的accentColor
有关 - 这对图像没有影响(它仍然消失了(,但确实摆脱了蓝色。有什么想法吗?
您可能需要将rederingMode
添加到图像中,如下所示:
PresentationButton(destination: CardStack()) {
Image("breast_image")
.renderingMode(.original)
.padding()
}
顺便说一句,这不是错误,Button
视图试图将提供的图像用作模板(用于渲染按钮状态(,并且需要知道您的图像应作为实际图像呈现。
请添加修改参数.buttonStyle(.plain(到按钮。在给定情况下代码必须为
PresentationButton(destination: ProfileHost()) {
CardView()
}.buttonStyle(.plain)