0

I want to dismiss my current view on the tap of an image but the tappable area of that image is bigger than the actual image (Blue background is also tappable as shown in the image), if I increase the image size the tappable area also increases, How can I remove the blue box around the image but still be able to increase image size?

 Image("Cancel")
      .resizable()
      .scaledToFit()
      .contentShape(Circle())
      .frame(width: 50, height: 50)

      .background(Color.blue)
      .onTapGesture {
      presentationMode.wrappedValue.dismiss()
      }

Button Image

1
  • SwiftPunk's answer is correct but I just copy-pasted what Paul Hudson taught in the course and it's absolutely perfect also it makes the surrounding frame the same size as of image Image("Cancel") .renderingMode(.original) .clipShape(Circle()) .overlay(Circle().stroke(Color.black,lineWidth: 1)) Commented Mar 24, 2021 at 20:24

1 Answer 1

0

You need to use clipShape like in code:


enter image description here

import SwiftUI

struct ContentView: View {
    var body: some View {

        Image(systemName: "xmark.circle")
            .resizable()
            .scaledToFit()
            .frame(width: 50, height: 50)
            .background(Color.blue)
            .contentShape(Circle())
            .clipShape(Circle())
            .onTapGesture {
                presentationMode.wrappedValue.dismiss()
            }
        
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.