Iphone 删除UITableViewCell上的填充
在带有Iphone 删除UITableViewCell上的填充,iphone,objective-c,cocoa-touch,Iphone,Objective C,Cocoa Touch,在带有UITableViewCellStyleSubtitle样式的UITableViewCellStyleSubtitle上,我正在设置imageView.image、textlab.text和detailtextlab.text。牢房四周都是白色的填充物。我如何去除填充物,使我的所有图像像下面的Youtube应用程序一样相互接触 最简单的方法可能是将UITableViewCell子类化,并覆盖-layoutSubviews方法来执行以下操作: - (void)layoutSubviews {
UITableViewCellStyleSubtitle
样式的UITableViewCellStyleSubtitle
上,我正在设置imageView.image
、textlab.text
和detailtextlab.text
。牢房四周都是白色的填充物。我如何去除填充物,使我的所有图像像下面的Youtube应用程序一样相互接触
最简单的方法可能是将
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
}
尝试在interface builder或代码中减少UITableView的行高,以便不存在填充。 我必须在tableview的界面生成器中增加填充。
不过,Daves answer可能会让您对修改单元格视图有更多的控制权。只需删除表分隔符:
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
在iOS8中,可以设置
tableView.layoutMargins = UIEdgeInsets.zero
在代码中,或从界面生成器中。此方法非常有效。有时它还需要在子视图上调用LayoutSubView,特别是在调整宽度或高度时。这是一个很好的解决方案!谢谢你应该把@Borut的答案标记为有效答案,因为它更简单,也是你问题的主要原因。在浪费了一整天时间之后!这个解决方案也对我有用: