我正在尝试使用UITableView创建一个排名表。
我创建了一个带有7个标签的自定义单元格。我使用分组细胞来区分AL Central,NL East等。
加载视图时,请查看此图片:
滚动视图时将其与图像进行比较:
这是我的代码(删除重复的代码):
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = @"Cell2";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}// end
//rank
UILabel *rank = (UILabel *)[cell viewWithTag:101];
//team
UILabel *team = (UILabel *)[cell viewWithTag:102];
if(indexPath.row == 0)
{
NSArray *division = @[@"AL Central", @"AL East", @"AL West", @"NL Central", @"NL East", @"NL West"];
rank.text = @"";
team.text = division[indexPath.section];
cell.backgroundColor = textPrimary;
team.textColor = backgroundPrimary;
team.font = [UIFont boldSystemFontOfSize:5.0f];
won.font = [UIFont boldSystemFontOfSize:11.0f];
return cell;
}
cell.backgroundColor = [UIColor clearColor];
rank.textColor = textPrimary;
team.textColor = textPrimary;
int new_row = indexPath.row + indexPath.section*5 - 1;
rank.text = [[[dataSource objectAtIndex:new_row] objectForKey:@"rank"] stringValue];
team.text = [[dataSource objectAtIndex:new_row] objectForKey:@"first_name"];
return cell;
}
答案 0 :(得分:0)
我解决了这个问题,当它不是标题时再次设置字体:
team.font = [UIFont systemFontOfSize:5.0f];