iPhone5情节提要自动布局

iPhone5情节提要自动布局,iphone,ios6,retina-display,autolayout,Iphone,Ios6,Retina Display,Autolayout,我正在使用autolayout编写一个iOS应用程序。 我想在屏幕Y中心下方30点处放置一个按钮。 如何为此添加约束?访问此链接,了解iOS 6.0自动布局中的“我的意思是约束”。@Ravindra,我之前已经通过了教程。但是我在里面找不到我的问题的答案。你找到了吗?@JohnSauer浏览了你的链接,很好的文章谢谢,没有办法在故事板上手动添加这个约束吗?没有。对于约束系统,您可以做很多事情,IB不提供设置控件。这是其中之一。 - (void)viewDidLoad { [super v

我正在使用autolayout编写一个iOS应用程序。 我想在屏幕Y中心下方30点处放置一个按钮。
如何为此添加约束?

访问此链接,了解iOS 6.0自动布局中的“我的意思是约束”。@Ravindra,我之前已经通过了教程。但是我在里面找不到我的问题的答案。你找到了吗?@JohnSauer浏览了你的链接,很好的文章谢谢,没有办法在故事板上手动添加这个约束吗?没有。对于约束系统,您可以做很多事情,IB不提供设置控件。这是其中之一。
- (void)viewDidLoad
{
    [super viewDidLoad];
    UIView *superView = self.view;
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    [button setTranslatesAutoresizingMaskIntoConstraints:NO];
    [button setTitle:@"Button" forState:UIControlStateNormal];
    [superView addSubview:button];

    // adding constraints to the button
    NSLayoutConstraint *cn = [NSLayoutConstraint constraintWithItem:button
                             attribute:NSLayoutAttributeTop
                             relatedBy:NSLayoutRelationEqual
                                toItem:superView
                             attribute:NSLayoutAttributeCenterY
                            multiplier:1.0
                              constant:30];// adds 30 points from Screen Center Y
    [superView addConstraint:cn];


    cn = [NSLayoutConstraint constraintWithItem:button
                                      attribute:NSLayoutAttributeCenterX
                                      relatedBy:NSLayoutRelationEqual
                                         toItem:superView
                                      attribute:NSLayoutAttributeCenterX
                                     multiplier:1.0
                                       constant:0.0];// places the button in middle of X axis
    [superView addConstraint:cn];

}