James
James

Reputation: 201

Any way of resizing UIImageView / Label Text Size based on iOS Device?

I am learning to use constraints in Interface Builder and have tried messing around with aspect ratio and width/height properties of UIImageViews. I was just curious if there was anyway to autoresize, sort of like "zoom" to prevent a lot of white space in bigger iPhones? (6 & 6Plus).

Example of what I mean:

enter image description here Notice the bigger devices have a lot of white space, would be nice to simply resize that UIImageView up top along with label based on device, sort of like I did with that bottom button by using aspect ratio. Any ideas?

Upvotes: 0

Views: 2587

Answers (1)

Amandir
Amandir

Reputation: 677

With IOS 8 apple introduced size classes as an addition to auto layout. https://developer.apple.com/library/ios/recipes/xcode_help-IB_adaptive_sizes/chapters/EnablingAdaptiveSizeDesign.html

With size classes you can have different user interfaces for different devices and different device orientations.

For The case you are describing (dynamically resizing of Views), you can also just go with the "old" basic auto layout functionality:

  1. Set Constraints of UIImageView to keep a fixed distance to the top Layout guide
  2. Set Constraint UIImageView to keep a fixed distance to your top UITExtField
  3. Center UIImageView in Container
  4. Set Fixed aspect Ratio of your Image

Tadaaa, you have an dynamically resizing Image that will always keep its aspect ration.

Upvotes: 1

Related Questions