Creating a percentage based iOS layout

后端 未结 5 1601
孤城傲影
孤城傲影 2020-11-29 20:37

I\'m trying to replicate a layout that I currently have in an Android application, but I don\'t know how to go about it in iOS especially because of the tallness of the iPho

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-29 21:12

    Using Xcode 6.0, you can now specify proportional width or height in Interface Builder. Steps for percentage height from superview:

    While both the child view and its superview are selected, add an "equal height" constraint (or "equal width" if you wish to have a proportional width).

    enter image description here

    Then change the "multiplier" of the constraint you just added to the proportion you need. For example, for 50%, change it to 2.

    If you like to specify the inner view as percentage of the superview, you can reverse the items in the constraint:

    enter image description here

    Now you can use a multiplier of 0.5 (or any other proportion you need):

    enter image description here

    In your specific case, you can define an "equal height" constraint between the 2 child views, and change the multiplier to 1.5 (the bottom being 1.5 the size of the top) or 0.6667 if the items are reversed.

提交回复
热议问题