Creating Auto Layout constraints to topLayoutGuide and bottomLayoutGuide in code

后端 未结 4 1304
无人共我
无人共我 2020-12-28 11:19

Apple\'s documentation on creating Auto Layout constraints between a view and one of the layout guides only shows an example using VFL.

Is there any way to create th

4条回答
  •  伪装坚强ぢ
    2020-12-28 11:59

    Just an addition to @Jamie McDaniel, in case it's not immediately obvious, you need to add the constraint that he suggests to create:

    NSLayoutConstraint *buttonTopConstraint = [NSLayoutConstraint constraintWithItem:self.button
                                     attribute:NSLayoutAttributeTop
                                     relatedBy:NSLayoutRelationEqual
                                        toItem:self.topLayoutGuide
                                     attribute:NSLayoutAttributeBottom
                                    multiplier:1.0
                                      constant:20.0];
    [self.view addConstraint:buttonTopConstraint];
    

提交回复
热议问题