NEW: Subscribe to Hacking with Swift+ and accelerate your learning! >>

Resizing Image in macOS SwiftUI app

Forums > macOS

My app displays an Image in a view. I want the user to be able to resize the Image. Please could someone give me some ideas on how I could achieve this? I think I probably need to use some sort of Gesture e.g. MagnificationGesture, but I can't see how to apply it to a macOS app.


What is the effect you are trying to achieve?

If it is to enable the user to look at the image in more detail, you might consider opening it in a new window so they can resize it, view and then close it when done? Having had a nose around Stack Overflow, I think this does not work natively in Swiftui yet and you would need to enlist some AppKit functionality.

If it's more a case of allowing the image to resize when the user changes the window size, you should be able to achieve that quite easily using the .resieable() modifier where you create the image view. You would then need to ensure you don't have a fixed frame size.

Something along the lines of : Image("myImage") .resizeable() .frame(minWidth: 200, minHeight: 200)

I guess this could be too simplistic but it's about the extent of my knowledge on this subject.


Hacking with Swift is sponsored by NSSpain

SPONSORED Announcing NSSpain 2020: Remote Edition! An online, continuous conference for iOS developers. We’ll start on Thursday and finish on Friday, with talks, activities, and lots of fun for 36 hours, non-stop. Sound good? Join us!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

Unknown user

Not logged in

Log in

Link copied to your pasteboard.