PresentationButton 在视图中隐藏图像
PresentationButton hides Image in View
我正在尝试将 PresentationButton
添加到包含一些 Text
和 Image
的视图 CardView。代码如下:
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 立即变为蓝色并且图像消失。所有文本不受影响。我认为这与 accentColor
有关,我立即切换到 Color.clear
- 这对图像没有影响(它仍然消失了)但确实摆脱了蓝色。有什么想法吗?
您可能希望将 rederingMode
添加到图像中,如下所示:
PresentationButton(destination: CardStack()) {
Image("breast_image")
.renderingMode(.original)
.padding()
}
顺便说一句,这不是错误,Button
视图尝试使用提供的图像作为模板(以呈现按钮状态)并且它需要知道您的图像应该呈现为实际图像而不是.
请给Button添加修改参数.buttonStyle(.plain)。在给定的情况下
代码必须是
PresentationButton(destination: ProfileHost()) {
CardView()
}.buttonStyle(.plain)
我正在尝试将 PresentationButton
添加到包含一些 Text
和 Image
的视图 CardView。代码如下:
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 立即变为蓝色并且图像消失。所有文本不受影响。我认为这与 accentColor
有关,我立即切换到 Color.clear
- 这对图像没有影响(它仍然消失了)但确实摆脱了蓝色。有什么想法吗?
您可能希望将 rederingMode
添加到图像中,如下所示:
PresentationButton(destination: CardStack()) {
Image("breast_image")
.renderingMode(.original)
.padding()
}
顺便说一句,这不是错误,Button
视图尝试使用提供的图像作为模板(以呈现按钮状态)并且它需要知道您的图像应该呈现为实际图像而不是.
请给Button添加修改参数.buttonStyle(.plain)。在给定的情况下 代码必须是
PresentationButton(destination: ProfileHost()) {
CardView()
}.buttonStyle(.plain)