changing the color of titleFor Header in section

后端 未结 4 1472
别那么骄傲
别那么骄傲 2021-02-10 18:14
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 

{

}

Hi
I am very new in objective c..................

相关标签:
4条回答
  • 2021-02-10 18:42

    Please use following code & change the color of your UITableView header

    -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
    {
        UIView *tempHeaderView=[[UIView alloc]initWithFrame:CGRectMake(0,0,320,44)];
        tempHeaderView.backgroundColor=[UIColor clearColor];
        UILabel *tempHeaderLabel=[[UILabel alloc]initWithFrame:CGRectMake(0,0,320,44)];
        tempHeaderLabel.backgroundColor=[UIColor clearColor];
        tempHeaderLabel.text=@"HEADER";
        [tempHeaderView addSubView: tempHeaderLabel];
        return tempHeaderView;
    }
    
    0 讨论(0)
  • 2021-02-10 18:53

    Beware that the view you return is not retained by the UITableView (OS 3.1.2 at least seems to display this problem). This leads to hard-to-find crashes that occur before execution gets to viewDidLoad.

    The table view doesn't grab your views on demand as you would think. It requests them all, then requests them all again, and sometimes several more times, so generating them on every request is very inefficient.

    0 讨论(0)
  • 2021-02-10 18:54

    You may try folowing: Header with two customized labels

    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:
                                                          (NSInteger)section {
        UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,
        tableView.bounds.size.width, 22)];
    
        NSString *dateStr = [[self.data allKeys] objectAtIndex:section];
        CGFloat labelWidth = tableView.bounds.size.width / 2;
        CGFloat padding = 5.0;
    
        UILabel *labelOne = [[UILabel alloc] initWithFrame:CGRectMake
                            (padding, 0, (labelWidth - padding), 22)];
        labelOne.backgroundColor = [UIColor clearColor];
        labelOne.textAlignment = UITextAlignmentLeft;
        labelOne.text = dateStr;
    
        UILabel *labelTwo = [[UILabel alloc] initWithFrame:CGRectMake
        (labelWidth, 0, (labelWidth - padding), 22)];
        labelTwo.backgroundColor = [UIColor clearColor];
        labelTwo.textAlignment = UITextAlignmentRight;
        labelTwo.text = @"This is Label TWO";
    
        [headerView addSubview:labelOne];
        [headerView addSubview:labelTwo];
    
        [labelOne release];
        [labelTwo release];
    
        return headerView;
    }
    
    0 讨论(0)
  • 2021-02-10 18:56

    Use tableView:viewForHeaderInSection: instead. That way you can configure a UILabel or whatever to your like (complete with font, transparency, color, etc), and the tableview will use that view as the header as opposed to the default view.

    0 讨论(0)
提交回复
热议问题