Question

Alright, So i am an uber noob at Developing but i am trying to learn Xcode. One thing i have yet to figure out is how to change the SectionHeader(Color Font's Etc.) I am using a TableView thats been embed in a Container. And Specifically speaking my Section headers are the alphabet A-Z and i am trying to make them "Helvetica Neue UltraLight" Font and Font Size 24. How would i go about changing the Font, Font Size, and Font Color.

Also i Am trying to change the background color of the Section Header to Completely clear.

I am using Xcode 4.6.3 Building an app for iOS 6.1.

Was it helpful?

Solution

Override tableView:viewForHeaderInSection: in your 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;
}

You will need to adjust the frame heights appropriately based on the text you want in the section header. Use NSString sizeWithFont:constrainedToSize:lineBreakMode: to calculate the correct height values.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top