Changing Font Size For UITableView Section Headers

前端 未结 11 775
借酒劲吻你
借酒劲吻你 2020-12-12 09:28

Can someone please instruct me on the easiest way to change the font size for the text in a UITableView section header?

I have the section titles implemented using t

11条回答
  •  萌比男神i
    2020-12-12 09:54

    For iOS 7 I use this,

    
    -(void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
    {
        UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
    
        header.textLabel.font = [UIFont boldSystemFontOfSize:10.0f];
        header.textLabel.textColor = [UIColor orangeColor];
    }
    

    Here is Swift 3.0 version with header resizing

    override func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
        if let header = view as? UITableViewHeaderFooterView {
            header.textLabel!.font = UIFont.systemFont(ofSize: 24.0)
            header.textLabel!.textColor = UIColor.orange          
        }
    }
    

提交回复
热议问题