Auto Layout

Auto Layout

XCode5+

Auto Layout Concepts

核心的概念是约束。

Constraint Basics

  • Constant value
  • Relation
  • Priority level

约束是累积的,重复定义一个按钮的宽度的约束不会覆盖上一个约束。因此你需要移除上一个约束。

Working with Constraints in Interface Builder(IB)

Interface Builder 简称IB

Adding Constraints

Control-Drag

当然我喜欢右击拉开,一样的效果。

Aligh and Pin 菜单

这个菜单在右下角。

Editing Constraints

Deleting Constraints

Canvas or in the outline view

Working with Auto Layout Programmatically

You can add constraints programmatically

Creating Constraints Programmatically

NSDictionary *viewsDictionary =
                NSDictionaryOfVariableBindings(self.button1, self.button2);
NSArray *constraints =
        [NSLayoutConstraint constraintsWithVisualFormat:@"[button1]-[button2]"
                            options:0 metrics:nil views:viewsDictionary];

Resolving Auto Layout Issues

On the canvas. Misplaced or ambiguous constraints are shown in orange, conflicting constraints are red,and red dotted frames show the predicted runtime positions of misplaced or ambiguous views.

  • Resolving View Misplacement
  • Resolving Constraint Conflicts

    Auto Layout by Example

未完待续

你可能感兴趣的:(layout)