I have three strings that I want to present in header of grouped tableview. Problem is I append this strings in tableView titleForHeaderInSection and I want to present each string in different line with different color and font.
What currently I have is :

What I want is:

I get and append those three string as following
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection: (NSInteger) section
{
NSString * presenter = [[self agenda] getBriefingPresenter:section];
NSString * time = [[self agenda] getBriefingTime:section];
NSString * subject = [[[[self agenda] getMeetingBriefings] objectAtIndex:section] objectForKey:@"subject"];
return [NSString stringWithFormat:@"%@\n%@ %@", subject, time, presenter ];
}
Method to handle the header font
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
if (sectionTitle == nil) {
return nil;
}
// Create label with section title
UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake(45, 0, 484, 23);
label.textColor = [UIColor whiteColor];
label.font = [UIFont fontWithName:@"Century Gothic" size:17];
label.text = sectionTitle;
label.lineBreakMode = UILineBreakModeWordWrap;
label.numberOfLines = 2;
[label sizeToFit];
label.backgroundColor = [UIColor clearColor];
// Create header view and add label as a subview
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100, 300, 320, 400)];
[view addSubview:label];
return view;
}
So how can I parse this sectionTitle and print as three different labels in three lines?
In
(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section, create 3 different labels with specific font and colors. You can’t set different fonts/colors on a single UILabel;So your code updated :
and you don’t need the
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection: (NSInteger) section