Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove padding on UITableViewCell

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?

like image 634
JoJo Avatar asked Mar 03 '26 04:03

JoJo


1 Answers

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
}
like image 70
Dave DeLong Avatar answered Mar 04 '26 17:03

Dave DeLong



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!