0

I have an array of images, these images can be taken from camera or photo library, so it can be on different sizes.

The images are displayed as thumbnails like on photo library, and my goal is to show one image on screen with a screen related size once it is tapped, then i can move to the next image with a gesture, also as the photo library.

My main problem is i don't know the size of an image view to fit the images on screen, i tried to scale them, but as i can have several sizes of images i can't find a pattern to scale (images of different sizes should be scaled differentially).

So, how can scale these images to fit on screen proportionally to it's size(again, like photo library)?

Cezar
  • 55,636
  • 19
  • 86
  • 87
douglasd3
  • 761
  • 2
  • 10
  • 27

2 Answers2

1

On UIImageView you can setup a scaling mode that should help fit the images onto the screen as nicely as possible. Essentially you want to "fit" the image onto the screen by either padding the small sides with empty space, or clipping the edges of the largest sides.

Keep imageView.frame uniform for all images and play with both of these options to find out what works best for your needs:

/* no clipping - empty space on sides */
imageView.contentMode = UIViewContentModeScaleAspectFit;

/* clipping - no empty space */
imageView.contentMode = UIViewContentModeScaleAspectFill;

An answer (scroll down) here illustrates the difference with a nice diagram: How to scale a UIImageView proportionally?

Community
  • 1
  • 1
Justin Meiners
  • 10,754
  • 6
  • 50
  • 92
0

did you already check the Collection View Controller? You use that kind of container type for your application.

http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/CollectionViewPGforIOS/Introduction/Introduction.html

Another way would be to add implement an own logic... You create several e.g UIImageView's and than implement an logic to detect the smallest one. Based on the smallest "frame" you resize the other Views till they match the size of the smallest UIImageView based on his height...

But I think its much more comfortable to use the collection container :D In addition here is an tutorial how to handle it if you dont want to read the full documentation from apple but I recommend to read it anyway!

http://www.raywenderlich.com/22324/beginning-uicollectionview-in-ios-6-part-12 this tutorial was created by Brandon Trebitowski

thank you best regards

Georg
  • 423
  • 3
  • 8