How to recreate the default UIView the same as the default tableView:viewForHeaderInSection:?

后端 未结 4 588
面向向阳花
面向向阳花 2021-02-04 16:58

I tried to implement the

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

to get the text label of the

4条回答
  •  余生分开走
    2021-02-04 17:42

    If you want to recreate the default / standard heightForHeaderInSection, use this:

    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
    {
        return 44;
    }
    
    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
    {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 44)];
    
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 11, tableView.frame.size.width-100, 21)];
    
        label.text = @"Text";
        label.textColor = [UIColor colorWithRed:76.0/255 green:86.0/255 blue:108.0/255 alpha:1];
        label.backgroundColor = [UIColor clearColor];
        label.font = [UIFont fontWithName:@"Helvetica-Bold" size:17.0];
    
        [view addSubview:label];
    
        return view;
    }
    

提交回复
热议问题