UITableView 改变titleForHeader默认文字效果

UITableView titleForHeader默认的文字都是灰色加阴影的,

如果换了其它BackgroundImage的话,就不搭了。

修改方法如下:

 

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    NSString *HeaderString = nil;
        
    switch (section) {
            case 0:
                HeaderString = [self.arraysrc objectAtIndex:section];
                break;
            case 1:
                HeaderString= [self.arraysrc objectAtIndex:section];
                break;
            case 2:
                HeaderString = [self.arraysrc objectAtIndex:section];
                break;
    }
   
    UIButton *HeaderButton=[[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 320, 40)] autorelease];
    [HeaderButton setTitle:HeaderString forState:UIControlStateNormal];
    [HeaderButton setBackgroundImage:[UIImage imageNamed:@"1.png"] forState:UIControlStateNormal];
    [HeaderButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];


    return HeaderButton;
}

 

如果还要改变titleForHeader的height method按着需要改变其高度

如下:

 

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{

 

     CGFloat height;

     switch(section)

     {

           case 0:

               height = 25.0;

               break;

           case 1:

               height = 25.0;

               break;

           case 2:

               height = 25.0;

               break;

           Default:

               break;

    }

    return height;

}

 

你可能感兴趣的:(UIView)