看一看Autolayout Visual Format Language。他們在去年的一些自動佈局的WWDC視頻中討論了這一點。
這不完整,但您需要定義垂直和水平方向的約束。這是完整的,但希望能給你一個流氓的想法,讓你開始。
// Vertical alignment should be centered
NSArray *constraints = [NSLayoutConstraint
constraintsWithVisualFormat:@"V:|[_imageView]-[_label1]-[_textBlock1]-[label2]-[textBlock2]-|"
options:NSLayoutFormatAlignAllCenterY
metrics:nil
views:viewsDictionary];
// Tell the views/text blocks to take the entire width. The labels will be fine centered on them I think
NSArray *constraints = [NSLayoutConstraint
constraintsWithVisualFormat:@"H:|-[_imageView]-|"
options:NSLayoutFormatAlignAllCenterY
metrics:nil
views:viewsDictionary];
NSArray *constraints = [NSLayoutConstraint
constraintsWithVisualFormat:@"H:|-[_textBlock1]-|"
options:nil
metrics:nil
views:viewsDictionary];
NSArray *constraints = [NSLayoutConstraint
constraintsWithVisualFormat:@"H:|-[_textBlock2]-|"
options:nil
metrics:nil
views:viewsDictionary];