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      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

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.