Is there any way to add constraint between a view and the top layout guide in a xib file?

后端 未结 7 2343
时光说笑
时光说笑 2020-12-07 15:44

In iOS 7, we can now add a constraint between a view and the top layout guide, which I think is very useful to solve the status bar offset issue in iOS7(especially when ther

7条回答
  •  醉酒成梦
    2020-12-07 16:09

    You should refer the following example, this will definitely help you for your problem. I got this from http://developer.apple.com .

    [button setTranslatesAutoresizingMaskIntoConstraints: NO];
    id topGuide = myViewController.topLayoutGuide;
    NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings (button, topGuide);
    
    [myViewController.view addConstraints:
        [NSLayoutConstraint constraintsWithVisualFormat: @"V:[topGuide]-20-[button]"
        options: 0
        metrics: nil
        views: viewsDictionary]
    ];
    

提交回复
热议问题