我使用 Masonry 设置 subview 的约束。
View Controller 很简单。
在viewDidLoad中
-(void)viewDidLoad
{
[self.view addSubview: self.tableView];
self.view.backgroundColor = [UIColor whiteColor];
[self.tableView addSubview: self.botBtn];
[self.botBtn makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(self.tableView.bottom).with.offset(-20);
make.centerX.equalTo(self.tableView);
}];
}
表格 View 的框架是CGRectMake(0,0,screen_width,screen_height), 但按钮位于屏幕之外,位于桌面 View 的顶部。
我在它的 init 方法中设置了 tableview 框架。 该按钮水平地停留在 View 的中间,因此自动布局似乎有效,但为什么它位于 tableview 的顶部而不是停留在底部。
最佳答案
首先使用 Masonry 做得很好 :D。
对于你的问题,我认为你没有以正确的方式添加按钮,我猜你想在 tableview 的底部添加一个按钮,所以当你滚动到 tableview 的底部时你会看到你的按钮吗?如果是这样,只需创建一个带有按钮的 UIView 并设置 tableview 的页脚 View ,即 [self.tableView setTableFooterView:newView];
如这个问题所述,Adding a button at the bottom of a table view
如果这不是您真正想要的,请告诉我,祝您好运。
关于ios - UIViewController 和自动布局 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39015164/