UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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.

3      

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.

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot 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.