Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can we change the font of tableview header?

I am using some background color for the tabelView and style is grouped. The text in the header for the sections is not clear so I need to modify the the text color so that the header text should be visible. I want to know can we change the header text's color and size?

like image 435
User97693321 Avatar asked Dec 09 '22 07:12

User97693321


1 Answers

Adding to terente's answer:

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        CGRect screenRect = [[UIScreen mainScreen] applicationFrame];
        UIView* headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenRect.size.width, 44.0)];
        //headerView.contentMode = UIViewContentModeScaleToFill;

        // Add the label
        UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(10.0, -5.0, 300.0, 90.0)];
        headerLabel.backgroundColor = [UIColor clearColor];
        headerLabel.opaque = NO;
        headerLabel.text = @"Header";
        headerLabel.textColor = [UIColor blackColor];
        headerLabel.highlightedTextColor = [UIColor blackColor];

        //this is what you asked
        headerLabel.font = [UIFont boldSystemFontOfSize:17];

        headerLabel.shadowColor = [UIColor clearColor];
        headerLabel.shadowOffset = CGSizeMake(0.0, 1.0);
        headerLabel.numberOfLines = 0;
        headerLabel.textAlignment = UITextAlignmentCenter;
        [headerView addSubview: headerLabel];

        [headerLabel release];  

        // Return the headerView
        return headerView;
    }
    else return nil;
}

You can use [UIFont fontWithName:@"<name of your font>" size:24.0]; for other fonts

like image 135
Bushra Shahid Avatar answered Jan 04 '23 06:01

Bushra Shahid