0

我将 2 个文本添加到表格的单元格中。我正在做的是

UITableViewCell *cell =nil;

NSString *CellIdentifier = @"Cell";

单元格 = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];

如果(细胞 == 零){

单元格 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];

[[UILabel alloc] initWithFrame:CGRectMake(80.0, 0.0, 220.0, 10.0)];

mainLabel.tag = 1003;

mainLabel.text = @"文本 1";

mainLabel.textAlignment = UITextAlignmentLeft;

mainLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin| UIViewAutoresizingFlexibleHeight; [cell.contentView addSubview:mainLabel];

}

我做同样的事情将 secondLabel 添加到单元格中。模拟器上显示的是 在此处输入图像描述

现在的问题是2 UILabel的背景与单元格的背景不一样(我的单元格在表格视图中分组)

有谁知道如何解决这个问题。

这里欢迎任何意见谢谢

4

2 回答 2

1

像上面的答案一样,您应该为两个视图设置相同的颜色。

cell.backgroundColor = [UIColor clearColor];

或者您可以设置您设置的视图的颜色。

于 2013-01-31T12:16:11.043 回答
1

如果我很好地理解了这个问题,您需要删除背景,UILabel因为您想显示UITableViewCell背景。所以我认为你只需要这样做:

 mainLabel.backgroundColor = [UIColor clearColor];
于 2012-05-03T15:56:35.880 回答