UIViewController和Autolayout子视图

时间:2016-08-18 09:55:47

标签: ios objective-c uiviewcontroller

我使用Masonry来设置子视图的约束。

视图控制器很简单。

在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);
    }];
}

表格视图的框架是CGRectMake(0,0,screen_width,screen_height), 但按钮位于屏幕之外,位于桌面视图的顶部。

我在其初始化方法中设置了tableview框架。 按钮水平停留在视图的中间,因此自动布局似乎有效,但为什么它位于桌面视图的顶部而不是停留在底部。

1 个答案:

答案 0 :(得分:1)

首先使用Masonry做得很好:D。

对于你的问题,我不认为你是以正确的方式添加按钮,我猜你想在tableview的底部添加一个按钮,所以当你滚动到tableview的底部你会看到你的按钮吗?如果是这样,只需使用按钮创建一个UIView并设置tableview的页脚视图,即[self.tableView setTableFooterView:newView];,如此问题中所述,Adding a button at the bottom of a table view

如果这不是你真正想要的,请告诉我,祝你好运。

相关问题