Search code examples
iosiphoneautolayoutxcode8

Change UImageView size using Autolayout


I have a imageview at the start and below there are series of buttons placed vertically one below the other. So, while designing the screen, I placed all the views in the view controller and added to vertical stack. Centred stack view horizontally and vertically. For all the buttons, I have set equal width. And in stack view, I have given equal spacing. In all iPhones, it is working correctly with ui elements arranged correctly with equal spaces except iPhone4. In iPhone 4 it is all touching each other. Please find the attachment. What constraint am I missing here?enter image description here


Solution

  • The problem is the content cannot be fitted in given height.

    Let me explain. Assume small device has height of 480. UIImageView height(intrinsic ) is say 200. You have 4 UIButton of height say 80. UILabel of height say 100. So that sums up to 620.

    Views of height 620 cannot fit(all visible without clipping) on a view of height 480.

    You need.

    1. Scrollview(To show more content than the available width and/or height)
    2. Reduce the size of you content to fit in 480. To do this you can pin the height of any/some/all to make this height sum less than or equal to 480.