NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

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 MadMachine

SPONSORED Want to explore your Swift skill outside of the Apple world? Join the MadMachine community and start to program microcontrollers in Swift.

Get it now

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.