删除UITableViewCell上的填充

JoJ*_*oJo 2 iphone cocoa-touch objective-c

在一个UITableViewCellUITableViewCellStyleSubtitle造型,我设置的imageView.image,textLabel.textdetailTextLabel.text.电池周围有白色衬垫.如何摆脱填充,以便我的所有图像都像下面的Youtube应用程序一样互相触摸?

Dav*_*ong 8

可能最简单的方法是子类化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
}
Run Code Online (Sandbox Code Playgroud)