2012-06-15 48 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