evgenyneu / Auk

An image slideshow for iOS written in Swift.
MIT License
277 stars 44 forks source link

Resizing url loaded image #73

Closed AkhilBabu349 closed 6 years ago

AkhilBabu349 commented 6 years ago

How to load images as adaptable for all device universally with equal width as the device

evgenyneu commented 6 years ago

Hi @AkhilBabu349, thanks for your question. Sorry, can you clarify what you mean by that? Maybe draw a picture? :)

AkhilBabu349 commented 6 years ago

The image loaded from url show different size as the device change ho to make it to same width in all device

AkhilBabu349 commented 6 years ago

simulator screen shot - iphone 5s - 2018-03-01 at 12 55 26 simulator screen shot - iphone 8 plus - 2018-03-01 at 12 58 36

See the image has been loaded in different sizes as the device is changed

evgenyneu commented 6 years ago

Thanks for the screenshots. A picture is worth a thousand words!

By default Auk uses .scaleAspectFit setting, which always shows the entire image without cropping. One can change that to .scaleAspectFill, and the image will fill the entire scroll view:

// Make the images fill entire page
scrollView.auk.settings.contentMode = .scaleAspectFill

In your case .scaleAspectFill will crop a little bit from the top and bottom of the image on wide devices. If you want to avoid cropping AND make images as wide as the screen, you will need to change the layout of your scroll view. If all your images have same aspect ratio, say 16:9, then one can use an auto layout constraint with this aspect ratio. This way, the scroll view will always be 16:9 and the images will fill it entirely with default .scaleAspectFit setting.

Let me know if it helps. :)

AkhilBabu349 commented 6 years ago

Yes it worked thank u : )

evgenyneu commented 6 years ago

No worries, I'm glad it worked!

eGirlAsm commented 6 years ago

same issue but already resolved thanks