我在UITableView中有一个UILabel。下面是我在cellForRowAtIndexPath中编写的代码。
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(30.0, 5.0, 250.0, 35.0) reuseIdentifier:CellIdentifier] autorelease];
}
CGRect rect = CGRectMake(30.0, 5.0, 250.0, 35.0);
UILabel *label = [[UILabel alloc] initWithFrame:rect];
label.opaque = NO;
label.font = [UIFont systemFontOfSize:14];
label.numberOfLines = 2;
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor darkGrayColor];
label.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
[label setText:@"Test Message"];
[cell addSubview:label];
[label release];
cell.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
我想将单元格和UILabel的背景设置为透明。
但是它并没有起作用。有人能告诉我我错过了什么吗?
谢谢
Sandeep
label.backgroundColor = nil;
更容易记住,并且具有相同的功能。(BG color是UIView超类的属性。根据类参考,“默认值为nil,这会导致背景色透明。”UILabel子类可能最初将其设置为白色,这就是为什么您必须显式将其更改为nil / clear的原因。) - Wienkelabel.backgroundColor = UIColor.clearColor()
。 - Xaren