【问题标题】:Updating frame of UITableViewCell Subview with AutoLayout使用 AutoLayout 更新 UITableViewCell 子视图的框架
【发布时间】:2014-06-26 04:49:19
【问题描述】:

我正在使用自动布局。我有一个 UIView 作为自定义 UITableViewCell 的子视图。在 cellForRow 中,我想在单元格中为 Row 设置 UIView 的框架。

这是我所拥有的:

UIView *bar;
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
               bar = (UIView *)[cell.contentView viewWithTag:2];
               [bar setFrame:CGRectMake(bar.frame.origin.x, 
                                        bar.frame.origin.y, 
                                                        10, 
                                     bar.frame.size.height)];

}

如果我关闭自动布局,它会起作用。如何使用自动布局来完成此操作?我已经彻底搜索了,但没有找到解决方案。

【问题讨论】:

    标签: uitableview autolayout subview


    【解决方案1】:

    您可以通过使用情节提要或界面构建器在这些工具中创建 uiview 来做到这一点,并使用约束来获得所需的视图大小。

    自动布局可以通过编程方式完成,但据我所知,这真的很烦人。自动布局的最佳方式是使用可视化构建工具。

    查看 uitableviewcell xib stackoverflow 帖子,了解如何去做。笔尖提示:

    [self.tableView registerNib:[UINib nibWithNibName:@"CustomTableViewCell" bundle:nil] forCellReuseIdentifier:@"customCellIdentifier"];
    

    【讨论】:

      猜你喜欢
      • 2015-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多