2013-10-07 99 views
2

enter image description here自動版式子視圖對齊到上海華中心X

如何子視圖對齊到上海華中心X?

我有兩個子視圖添加到調整大小能夠超視圖。 子視圖A要追蹤對齊到超級視圖中心X和 子視圖B想要導致超級視圖的中心X.

由於這種情況我該怎麼辦?

感謝

回答

1

你可以嘗試用以下方式添加的約束(NSLayoutConstraint class reference):

[superview addConstraint:[NSLayoutConstraint constraintWithItem:subviewA 
       attribute:NSLayoutAttributeTrailing 
       relatedBy:NSLayoutRelationEqual 
        toItem:superview 
       attribute:NSLayoutAttributeCenterX 
       multiplier:1.0 
       constant:0.0]]; 

[superview addConstraint:[NSLayoutConstraint constraintWithItem:subviewB 
       attribute:NSLayoutAttributeLeading 
       relatedBy:NSLayoutRelationEqual 
        toItem:superview 
       attribute:NSLayoutAttributeCenterX 
       multiplier:1.0 
       constant:0.0]];