Take the 2-minute tour ×

I have two subviews, an UILabel and an UIImageView, which I would like to center in a view. They should be placed next to each other and together they should be in the center of their superview whose width is known.

I would also like to be able to add some spacing between the views.

Is this possible with auto layout?

|           Superview         |
|                             |
|     [label] [imageview]     |
share|improve this question

1 Answer 1

up vote -2 down vote accepted

wrap the label & imageview in a wrapview

then autoresize the wrapview using

view.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;

enter image description here

share|improve this answer
This way, I will have to manually change the size of the wrapview when the width of the label changes, right? –  simonbs Apr 19 '13 at 17:54
yes, if the label is not fixed, or there's no way to autolayout :) –  adali Apr 19 '13 at 17:56

Your Answer


