How to change text color for Section Headers in a Grouped TableView in iPhone SDK?

后端 未结 7 1468
情深已故
情深已故 2020-12-14 08:10

I am making an iPhone app where in I have a grouped TableView with headers for the sections.

Problem is that I want to change the Section Header\'s text color.

7条回答
  •  天命终不由人
    2020-12-14 09:02

    This is SURELY gonna work for you.

    -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
    {
        UIView *tempView=[[UIView alloc]initWithFrame:CGRectMake(0,200,300,244)];
        tempView.backgroundColor=[UIColor clearColor];
    
        UILabel *tempLabel=[[UILabel alloc]initWithFrame:CGRectMake(15,0,300,44)];
        tempLabel.backgroundColor=[UIColor clearColor]; 
        tempLabel.shadowColor = [UIColor blackColor];
        tempLabel.shadowOffset = CGSizeMake(0,2);
        tempLabel.textColor = [UIColor redColor]; //here you can change the text color of header.
        tempLabel.font = [UIFont fontWithName:@"Helvetica" size:fontSizeForHeaders];
        tempLabel.font = [UIFont boldSystemFontOfSize:fontSizeForHeaders];
            tempLabel.text=@"Header Text";
    
        [tempView addSubview:tempLabel];
    
        [tempLabel release];
        return tempView;
    }
    

    just copy and paste this function in your code.

提交回复
热议问题