Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PresentationButton hides Image in View

Tags:

swiftui

I’m trying to add a PresentationButton to a view CardView that contains some Text and Image. Code is shown below:

PresentationButton(destination: ProfileHost()) {
   CardView()
}

Here is my CardView implementation:

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)
    }
}

As soon as I run the preview, the CardView turns blue and the image disappears. All the text stays unaffected. I thought this had something to do with the accentColor which I promptly switched to Color.clear - this had no effect on the image (it was still gone) but did get rid of the blue color. Any ideas?

like image 919
cyril Avatar asked Mar 07 '26 01:03

cyril


2 Answers

You may want to add rederingMode to the image as follows :

PresentationButton(destination: CardStack()) {
    Image("breast_image")
        .renderingMode(.original)
        .padding()
}

Btw, it's not a bug, the Button view tries to use the supplied image as a template (to render button states) and it needs to know that your image should be rendered as an actual image instead.

like image 145
Bogdan Farca Avatar answered Mar 09 '26 15:03

Bogdan Farca


Please add the modify parameter .buttonStyle(.plain) to Button. In the given case the code has to be

PresentationButton(destination: ProfileHost()) { CardView() }.buttonStyle(.plain)

like image 34
Suryanarayan Sahu Avatar answered Mar 09 '26 15:03

Suryanarayan Sahu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!