2012-06-15 30 views
0

类似的问题:How to mimic UITableView's UITableViewStylePlain section header style
没有完整的答案。 BarrettJ's很近,但并不完全。UITableViewPlain的默认区域标题?

图像似乎是最简单,最有效的方法,但我无法获得正确的尺寸/位置,即使当我接近时,它在第一个和第二个标头中看起来仍然不同。 (与桌面视图顶部有什么不同?)

文本不是问题。我只需要一些东西来填充空间,并且看起来与默认标题完全相同。

回答

1
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 
    UIView *sectionHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, tableView.sectionHeaderHeight)]; 
    sectionHeaderView.backgroundColor = [UIColor colorWithWhite:0 alpha:0]; 
    sectionHeaderView.userInteractionEnabled = YES; 
    sectionHeaderView.tag = section; 

    UIImageView *backgroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, -1, tableView.bounds.size.width, 23)]; 
    backgroundImageView.image = [UIImage imageNamed:@"header.png"]; 

    UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(12, 2, tableView.bounds.size.width-10, 18)]; 
    headerLabel.backgroundColor = [UIColor clearColor]; 
    headerLabel.textColor = [UIColor whiteColor]; 
    headerLabel.shadowColor = [UIColor darkGrayColor]; 
    headerLabel.shadowOffset = CGSizeMake(0, 1); 
    headerLabel.font = [UIFont boldSystemFontOfSize:18]; 
    headerLabel.text = [self tableView:tableView titleForHeaderInSection:section]; 

    [sectionHeaderView addSubview:backgroundImageView]; 
    [sectionHeaderView addSubview:headerLabel]; 

    return sectionHeaderView; 
} 

修好了。任何人都可以使用/修改这个。

header.png

+0

什么是header.png? – Irina