【问题标题】:Remove padding on UITableViewCell删除 UITableViewCell 上的填充
【发布时间】:2011-04-24 07:03:06
【问题描述】:

在带有UITableViewCellStyleSubtitle 样式的UITableViewCell 上,我设置了imageView.imagetextLabel.textdetailTextLabel.text。单元格周围有白色填充物。如何摆脱填充,以便我的所有图像像下面的 Youtube 应用程序一样相互接触?

【问题讨论】:

  • 您应该将@Borut 的答案标记为有效的答案,因为它更简单,也是您问题的主要原因。
  • 在这上面浪费了一整天!这个解决方案也对我有用:stackoverflow.com/questions/19103155/…

标签: iphone objective-c cocoa-touch


【解决方案1】:

可能最简单的方法是继承UITableViewCell 并覆盖-layoutSubviews 方法以执行以下操作:

- (void)layoutSubviews {
  //have the cell layout normally
  [super layoutSubviews];
  //get the bounding rectangle that defines the position and size of the image
  CGRect imgFrame = [[self imageView] frame];
  //anchor it to the top-left corner
  imgFrame.origin = CGPointZero;
  //change the height to be the height of the cell
  imgFrame.size.height = [self frame].size.height;
  //change the width to be the same as the height
  imgFrame.size.width = imgFrame.size.height;
  //set the imageView's frame (this will move+resize it)
  [[self imageView] setFrame:imgFrame];

  //reposition the other labels accordingly
}

【讨论】:

  • 这种方法效果很好。有时它还需要在子视图上调用 layoutSubviews,尤其是在调整宽度或高度时。
【解决方案2】:

只需删除表格分隔符:

self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

【讨论】:

  • 很好的解决方案!谢谢!
【解决方案3】:

在iOS8中可以设置

tableView.layoutMargins = UIEdgeInsets.zero

在代码中,或来自 Interface Builder。

【讨论】:

    【解决方案4】:

    尝试在界面生成器或代码中减少 UITableView 的行高,以便没有填充。 我不得不增加我在 tableview 的界面构建器中这样做的填充。 但是 Daves 的回答可能会让您更好地控制修改单元格视图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-24
      • 2017-06-16
      • 2015-04-21
      • 2014-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多