删除UITableViewCell上的填充 [英] Remove padding on UITableViewCell
本文介绍了删除UITableViewCell上的填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 UITableViewCell
与 UITableViewCellStyleSubtitle
样式,我设置 imageView.image
, textLabel.text
和 detailTextLabel.text
。单元格周围有白色填充。如何摆脱填充,所有我的图像互相接触,像下面的Youtube应用程序?
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?
推荐答案
可能最简单的方法是子类 UITableViewCell
-layoutSubviews
方法执行此操作:
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
}
这篇关于删除UITableViewCell上的填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文