1

我的应用看起来就像 iphone 上的默认通讯簿应用。对于每个字母,地址簿中都有一个节标题(A,B . .),灰色渐变背景色。是否可以将该默认颜色覆盖为其他色调?

4

2 回答 2

4
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    // create the parent view that will hold header Label
    UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 25.0)];

    // create the button object
    UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    headerLabel.backgroundColor = [UIColor blackColor];
    headerLabel.opaque = NO;
    headerLabel.textColor = [UIColor whiteColor];
    headerLabel.highlightedTextColor = [UIColor whiteColor];
    headerLabel.font = [UIFont boldSystemFontOfSize:20];
    headerLabel.frame = CGRectMake(0.0, 0.0, 320.0, 22.0);

    // If you want to align the header text as centered
    //headerLabel.frame = CGRectMake(150.0, 0.0, 300.0, 44.0);

    headerLabel.text = @"Name of header";

    [customView addSubview:headerLabel];

    return customView;

}
于 2010-07-28T05:52:56.367 回答
1

您可以通过在 UITableViewDelegate 中实现以下方法来替换 UITableView 的节标题:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

您可能还希望实现 height 方法以确保您的新剖面视图正确显示:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

要更改节标题的颜色,请创建一个 UIView,其中包含一个 UIImageView,并为该节的文本创建一个 UILabel。将图像添加到 UIImageView 以了解您希望背景的外观。

AFAIK,您无法操纵剖面图的 tintColor 。

于 2010-07-27T14:30:47.903 回答