Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS how to center two view via PureLayout

I want to center my UIImageView and UILabel like the pic below. I used a container to contain UIImageView and UILabel,but the container does not suit the width of UIImageView and UILabel.So I need to set the width of the container.Is there any method to solve the problem without set the width or calculate the view's width? Here's the picture:

MyLabel

like image 380
Kevin Hawk Avatar asked Mar 24 '15 08:03

Kevin Hawk


1 Answers

There are four view in action:

  1. Outer or main view
  2. Container view (contains image and label)
  3. Image view
  4. Label view

The views are in following hierarchy:

  1. Outer view
    1. Container View
      1. Image view
      2. Label view

I assume that the outer view gets its width and height from other constraints.

What I see from the image you provided that image is taller than label, keeping that in mind following constrains could achieve what you want:

  1. Align X axis of container view to outer view
  2. Align Y axis of container view to outer view
  3. Pin top, left and bottom edge of Image view to container view
  4. Pin right edge of label to container view
  5. Align Y axis of label to container view.
  6. Set horizontal distance between image and label view.
like image 67
Abdullah Avatar answered Sep 20 '22 02:09

Abdullah