【问题标题】:Flexible layout using interface builder使用界面构建器的灵活布局
【发布时间】:2014-05-02 11:44:20
【问题描述】:

我想实现这种布局,它会在横向模式下调整宽度,并保持所有空间(间隙)的定义。所以一行UITextView的单列有两列,当减去左右和中间的间隙时,应该占左边宽度的一半。

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

我尝试了很长时间检查不同的约束,例如宽度 = 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

【问题讨论】:

    标签: ios interface-builder autolayout


    【解决方案1】:

    围绕您想要居中的内容添加其他视图。

    +-----------------------------------------------+
    |                     <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
    

    【讨论】:

    • 这如何帮助我让所有文本字段使用所有可用宽度(减去左右间隙)?我应该在界面生成器中进行哪些约束设置?
    猜你喜欢
    • 2014-09-08
    • 1970-01-01
    • 2018-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-13
    • 2020-04-22
    • 1970-01-01
    相关资源
    最近更新 更多