【发布时间】:2011-11-10 13:48:49
【问题描述】:
当我的单元格突出显示时,我遇到了一个奇怪的问题。
只是为了更好的给大家介绍一下问题是什么,看看这两张图:
这是未选中时单元格的外观(正常状态):http://cl.ly/0n193u3U1o403x1s0m3z
这是单元格突出显示时的外观(在点击期间):http://cl.ly/1o2U400D3L0b3n3m1N1J
如您所见,当单元格被选中时,第二个标签的背景似乎被忽略了。 我不希望这种情况发生。我只想让第二个标签保持原样。
这就是我创建单元格的方式(有几种类型,每种都使用不同的单元格标识符)。
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellTableIdentifier] autorelease];
cell.backgroundView = [[[UIView alloc] init] autorelease];
}
switch (indexPath.section) {
...
...
case kTableSectionPending:
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(10, 10, self.tableView.frame.size.width - 20, 30.0)] autorelease];
UILabel *label2 = [[[UILabel alloc] initWithFrame:CGRectMake(10, 50, self.tableView.frame.size.width - 20, 30.0)] autorelease];
label.text = NSLocalizedString(@"IncompletePath", @"");
label.font = [UIFont boldSystemFontOfSize:16];
label.textAlignment = UITextAlignmentCenter;
label.backgroundColor = [UIColor clearColor];
label.layer.cornerRadius = 10;
FFRoute *lastPoint = ((FFRoute *) [[[FFSQLite sharedSingleton] getRoutesFromItinerary:itinerary] lastObject]);
label2.text = [NSString stringWithFormat:@"%@: %@", NSLocalizedString(@"LastPoint", @""), [self getStringFromTimestampOfFFRoute:lastPoint]];
label2.font = [UIFont systemFontOfSize:15];
label2.textAlignment = UITextAlignmentCenter;
label2.textColor = [UIColor whiteColor];
label2.backgroundColor = [UIColor colorWithRed:68/255.f green:82/255.f blue:124/255.f alpha:1];
label2.layer.cornerRadius = 10;
[label2 setOpaque:YES];
[cell.contentView addSubview:label];
[cell.contentView addSubview:label2];
// Set up background color
UIColor *bgcolor = [UIColor colorWithRed:250/255.f green:212/255.f blue:137/255.f alpha:1];
cell.backgroundView.backgroundColor = bgcolor;
break;
}
我尝试将 Opaque 属性设置为 true,但没有成功。
我错过了什么?谢谢
【问题讨论】:
标签: iphone uitableview background label