我有一个UITableView,目前它有一个单元格。我编写了一个自定义的TableViewCell类,它继承自UITableViewCell以执行一些自定义绘图。我已经将表格的宽度设置为所需的大小,并试图将单元格的宽度设置为相同的大小,因此它将填满表格的整个宽度。问题似乎是我在单元的左右两侧留有一些边距,我不知道为什么。iOS UITableView意外增加边距
Here's an example of the problem. 我使TableView背景变黑更清晰。 TableView是正确的大小。背景图像被添加到单元格中,而不是表格,并且它应占据表格的整个宽度。
我试图让TableView变宽(与屏幕一样宽)以尝试适应背景图像的大小,但这并不完全。我宁愿找出这些利润来自哪里,以及如何摆脱它们。
TableView本身在Interface Builder中初始化。样式设置为分组,滚动禁用,视图模式设置为缩放至填充。
这里的电池类的initWithStyle方法
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
// Initialization code
_primaryLabel = [[UILabel alloc] init];
_primaryLabel.textAlignment = UITextAlignmentLeft;
_primaryLabel.font = [UIFont systemFontOfSize:18];
_primaryLabel.backgroundColor = [UIColor clearColor];
_detailLabel = [[UILabel alloc] init];
_detailLabel.textAlignment = UITextAlignmentLeft;
_detailLabel.font = [UIFont systemFontOfSize:12];
_detailLabel.backgroundColor = [UIColor clearColor];
_icon = [[UIImageView alloc] init];
[self.contentView addSubview:_primaryLabel];
[self.contentView addSubview:_detailLabel];
[self.contentView addSubview:_icon];
self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
UIImageView* whiteDisclosureView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 15, 13)];
[whiteDisclosureView setImage:[UIImage imageNamed:@"white_disclosure.png"]];
self.accessoryView = whiteDisclosureView;
UIImageView * background = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 305, 61)];
[background setImage:[UIImage imageNamed:@"button_silver.png"]];
[self setBackgroundView:background];
self.backgroundColor = [UIColor clearColor];
self.frame = self.contentView.frame = CGRectMake(0, 0, 305, 61);
}
return self;
}
这就是问题所在。随着IB的调整,它按照我的预期工作。谢谢! – mayonaise 2012-02-22 02:22:33