【问题标题】:Change the UIView height which is inside the UITableViewCell更改 UITableViewCell 内的 UIView 高度
【发布时间】:2016-04-18 11:12:05
【问题描述】:

我正在尝试更改 tableView 内部的 UIView 高度。 UIView 高度不应超过单元格高度。

我试图设置view 的边界,但它没有影响视图。

我该如何解决这个问题并改变view的高度

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];


    UIView *view=(UIView *)[cell viewWithTag:999];

    view.backgroundColor=[UIColor redColor];
    [view setBounds:CGRectMake(view.bounds.origin.x, view.bounds.origin.y, view.bounds.size.width, 400)];

    return cell;
} 

【问题讨论】:

  • 但背景颜色按我的预期改变了
  • 您必须增加与您的视图相关的表格单元格高度。如果您使用的是自动布局,请使用布局约束。
  • 你能解释一下如何访问 cellForRowAtIndexPath 中的布局约束
  • 您必须在单元格内创建视图的 NSLayoutConstraint。或者你可以增加细胞的高度。并为视图提供底部约束。
  • 如果要改变单元格中控件的高度,那么同时也需要改变单元格的高度。

标签: ios objective-c uitableview uiview


【解决方案1】:

我找到了另一种方法。将标识符添加到视图高度约束。我可以像这样在控制器中访问它..链接-> Is there a way to add an identifier to Auto Layout Constraints in Interface Builder?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-19
    • 2021-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-15
    相关资源
    最近更新 更多