Uiview扩展代码
Visual Format Syntax
Width Constraint
Connection to Superview
Vertical Layout
Flush Views
Priority
Equal Widths
Multiple Predicates
A Complete Line of Layout
Visual Format String Grammar
The following are examples of constraints you can specify using the visual format. Note how the text visually matches the image.
Standard Space
[button]-[textField]

[button(>=50)]

|-50-[orchidBox]-50-|

V:[topField]-10-[bottomField]

[maroonView][oceanView]

[button(100@20)]

[button1(==button2)]

[flexibleButton(>=70,<=100)]

|-[find]-[findNext]-[findField(>=20)]-|

The notation prefers good visualization over completeness of expressibility. There are constraints that cannot be expressed in visual format syntax, although most of the constraints that are useful in real user interfaces can be. One useful constraint that cannot be expressed is a fixed aspect ratio (for example,imageView.width = 2 * imageView.height). To create such a constraint, you must use
constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:.
Visual Format String Grammar
The visual format string grammar is defined as follows (literals are shown in code font; e denotes the empty string).
Symbol
Replacement rule
<visualFormatString>
(<orientation>:)?
(<superview><connection>)?
<view>(<connection><view>)*
(<connection><superview>)?
<orientation>
H|V
<superview>
|
<view>
[<viewName>(<predicateListWithParens>)?]
<connection>
e|-<predicateList>-|-
<predicateList>
<simplePredicate>|<predicateListWithParens>
<simplePredicate>
<metricName>|<positiveNumber>
<predicateListWithParens>
(<predicate>(,<predicate>)*)
<predicate>
(<relation>)?(<objectOfPredicate>)(@<priority>)?
<relation>
==|<=|>=
<objectOfPredicate>
<constant>|<viewName>
(see note)
<priority>
<metricName>|<number>
<constant>
<metricName>|<number>
<viewName>
Parsed as a C identifier.
This must be a key mapping to an instance of NSView in the passed views dictionary.
<metricName>
Parsed as a C identifier. This must be a key mapping to an instance of NSNumber in the passed metrics dictionary.
<number>
As parsed by strtod_l, with the C locale.
Note: For the objectOfPredicate production, a viewName is only acceptable if the subject of the predicate is the width or height of a view. That is, you can use[view1(==view2)] to specify that view1 and view2 have the same width.