使用界面构建器灵活布局

时间:2014-05-02 11:44:20

标签: ios interface-builder autolayout

我希望实现这种布局,它将在横向模式下调整宽度,并保留所定义的所有空间(间隙)。因此,在一行中UITextView的单列有两个,当左侧和左侧之间的宽度的一半应该被扣除。

+---------------------------------------------+
|                     <y>                     |
|    +-----------------------------------+    |
|    |                                   |    |
|    +-----------------------------------+    |
|    +-----------------------------------+    |
|    |                                   |    |
|    +-----------------------------------+    |
|    +----------------+ +----------------+    |
|<x> |        50%     | |      50%       | <x>|
|    +----------------+ +----------------+    |
|    +-----------------------------------+    |
|    |                                   |    |
|    +-----------------------------------+    |
|                                             |
+---------------------------------------------+

我试了很长时间检查宽度&lt; = 280和width&gt; = 280等不同的约束 - 两者都有相同的结果。

有人可以一步一步地写下如何进行此布局吗?是否在UIScrollView

内是否重要?

结构是:

View
   Scroll View
      Content View
           Round Style Text Field
           Round Style Text Field
           View
               Round Style Text Field
               Round Style Text Field
           Round Style Text Field

1 个答案:

答案 0 :(得分:0)

围绕您想要居中的位置添加其他视图。

+-----------------------------------------------+
|                     <y>                       |
|    +-------------------------------------+    |
|    |+-----------------------------------+|    |
|    ||                                   ||    |
|    |+-----------------------------------+|    |
|    |+-----------------------------------+|    |
|    ||                                   ||    |
|    |+-----------------------------------+|    |
|    |+----------------+ +----------------+|    |
|<x> ||        50%     | |      50%       || <x>|
|    |+----------------+ +----------------+|    |
|    |+-----------------------------------+|    |
|    ||                                   ||    |
|    |+-----------------------------------+|    |
|    +-------------------------------------+    |
|                                               |
+-----------------------------------------------+

在另一个视图中将视图居中很容易。

View
    Scroll View
        Content View
            View
                Round Style Text Field
                Round Style Text Field
                View
                    Round Style Text Field
                    Round Style Text Field
                Round Style Text Field