我已经使用了几天的自动布局,并且我试图在屏幕中垂直和水平居中放置一个UILabel,但我没有太多的运气让标签居中。如何使用自动布局在屏幕中水平和垂直放置UILabel?
我希望能实现的东西,看起来像下面
---------------
| |
| |
| |
| |
| Label |
| |
| |
| |
| |
| SIGNIN REG |
---------------
我增加了以下约束到的UILabel,
NSLayoutConstraint *myLabelConstraintHeight = [NSLayoutConstraint constraintWithItem:myLabel
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.0f
constant:100];
[myLabel addConstraint:myLabelConstraintHeight];
NSLayoutConstraint *myLabelConstraintWidth = [NSLayoutConstraint constraintWithItem:myLabel
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1.0f
constant:100];
[myLabel addConstraint:myLabelConstraintWidth];
NSLayoutConstraint constraintWithItem:myLabel 属性:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:myLabel。 superview 属性:NSLayoutAttributeCenterX 乘数:1.f常数:0.f]; 对Y中心做同样的工作 – Vig