iOS: Auto Layout vs autoresizingMask - resizing whole view to fill?

纵然是瞬间 提交于 2019-12-03 14:22:30

To accomplish the same thing using constraints you need to set the leading, trailing, top and bottom space to the superview to 0. See below:

//load the ButtonGridViewController from a xib
[[NSBundle mainBundle] loadNibNamed:@"..." owner:self options:nil];

//get the view add it
[self.view addSubView:self.myGridView];

//turn off springs and struts
[self.view setTranslatesAutoresizingMaskIntoConstraints:NO];

//add constraints to fill parent view
NSArray *arr;

//horizontal constraints
arr = [NSLayoutConstraint constraintsWithVisualFormat:@"|[vw]|"
                                                options:0
                                                metrics:nil
                                              views:@{@"vw":self.myGridView}];
[self.view addConstraints:arr];

//vertical constraints
arr = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[vw]|"
                                                options:0
                                                metrics:nil
                                                  views:@{@"vw":self.myGridView}];
[self.view addConstraints:arr];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!