Xcode 6 - create UIImageView with equal heights ch

2019-05-26 16:46发布

问题:

Why doesn't the height of my UIImage change when I run it on a different device? I set the height to 187 too all 4 images and I want display them with equal heights so they fill the full screen?

Here's the constraints for each image:

The image on the right is a screen-shot taken from Xcode. The image on the left is a screen-shot on iPhone 6

回答1:

UIImage's size doesn't change because it's the same JPG/PNG file, regardless of the device. What you need is a set of proper layout constraints.

I suggest the following approach:

  1. Connect first image view's top to superview's top,
  2. Connect last image view's bottom to superview's bottom,
  3. Set equal heights for all image views.

Oh, and don't forget to set some constraints for horizontal axis.



回答2:

Add the constraints as the image below

Select all of the image first and give constraint as below

Step 1

Step 2

Step 3: You will achieve what you wants