如何定制SectionHeader



好吧,所以我是一个超级新手在开发,但我正在努力学习Xcode。我还没有弄清楚的一件事是如何改变SectionHeader(颜色字体等)我使用的TableView已嵌入到一个容器。具体来说,我的Section标题是字母A-Z,我试图让他们"Helvetica Neue UltraLight"字体和字体大小24。如何更改字体,字体大小和字体颜色?

我也试图改变背景颜色的部分标题完全清除。

我正在使用Xcode 4.6.3构建iOS 6.1的应用程序

重写tableView:viewForHeaderInSection:在你的UITableViewController:

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
      UIFont *font = [UIFont fontWithName:@"Helvetica Neue UltraLight" size:24];
      UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 3, tableView.bounds.size.width - 10, 33)];
      label.font = font;
      label.textColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.75];
      label.backgroundColor = [UIColor clearColor];
      label.text = @"A";
      UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, TableView.bounds.size.width, 44)];
      [headerView addSubview:label];
      [headerView setBackgroundColor:[UIColor clearColor]];
      return headerView;
}

你需要根据你想要在section header中的文本适当地调整框架高度。使用NSString sizeWithFont:constrainedToSize:lineBreakMode:来计算正确的高度值

最新更新