Remove padding on UITableViewCell

2020-03-06 03:35发布

On a UITableViewCell with UITableViewCellStyleSubtitle styling, I'm setting the imageView.image, textLabel.text, and detailTextLabel.text. There's white padding all around the cell. How do I get rid of the padding so all my images touch each other like the Youtube app below?

4条回答
Fickle 薄情
2楼-- · 2020-03-06 03:48

In iOS8 you can set

tableView.layoutMargins = UIEdgeInsets.zero

in code, or from Interface Builder.

查看更多
趁早两清
3楼-- · 2020-03-06 03:51

Just remove table separator:

self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
查看更多
老娘就宠你
4楼-- · 2020-03-06 03:54

Probably the easiest way to do this would be to subclass UITableViewCell and override the -layoutSubviews method to do something like this:

- (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
}
查看更多
Anthone
5楼-- · 2020-03-06 04:00

Try reducing the UITableView's row height in interface builder or code so that there is no padding. I had to increase the padding i did so in the interface builder for the tableview. However Daves answer might give you more control over modifying the cell view.

查看更多
登录 后发表回答