【问题标题】:UIViewController and Autolayout subviewsUIViewController 和 Autolayout 子视图
【发布时间】:2016-08-18 09:55:46
【问题描述】:

我正在使用 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);
    }];
}

table view 的框架是 CGRectMake(0,0,screen_width,screen_height), 但按钮在屏幕之外,就在 tableview 的顶部。

我在它的 init 方法中设置了 tableview 框架。 该按钮水平保持在视图的中间,因此自动布局似乎可以工作,但为什么它位于 tableview 的顶部而不是留在底部。

【问题讨论】:

    标签: ios objective-c uiviewcontroller


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-21
      • 2016-02-06
      相关资源
      最近更新 更多