【问题标题】:Default section header for UITableViewPlain?UITableViewPlain 的默认部分标题?
【发布时间】:2012-06-15 15:49:29
【问题描述】:

类似问题:How to mimic UITableView's UITableViewStylePlain section header style
没有完整的答案。 BarrettJ's 就在附近,但并不完全在那里。

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

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

【问题讨论】:

    标签: xcode uitableview header


    【解决方案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;
    }
    

    修复它。任何人都可以使用/修改它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      • 2012-02-03
      • 1970-01-01
      • 2016-10-24
      • 1970-01-01
      相关资源
      最近更新 更多