How can we change the font of tableview header?

前端 未结 5 993
灰色年华
灰色年华 2021-01-30 07:51

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

5条回答
  •  有刺的猬
    2021-01-30 08:29

    Just implement

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

    And return your custom view for header.

    Edit:

    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
        UIImageView *headerTitleView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, kSectionHeaderHeight)];
        [headerTitleView setImage:sectionHeaderBackgroundImage];
    
        UILabel *sectionTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake((self.view.frame.size.width - 38) / 2, 5, 38, kSectionHeaderHeight - 10)];
        sectionTitleLabel.textColor = [UIColor redColor];
        sectionTitleLabel.backgroundColor = [UIColor clearColor];
        sectionTitleLabel.textAlignment = UITextAlignmentCenter;
        sectionTitleLabel.text = @"A";
        sectionTitleLabel.font = [UIFont fontWithName:@"yourFont" size:13];
        [sectionTitleLabel setAdjustsFontSizeToFitWidth:YES];
        [headerTitleView addSubview:sectionTitleLabel];
    
        return headerTitleView;
    }
    

提交回复
热议问题