changing the color of titleFor Header in section

后端 未结 4 1476
别那么骄傲
别那么骄傲 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: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;
    }
    

提交回复
热议问题