How to change font color of the title in grouped type UITableView?

前端 未结 6 1599
轮回少年
轮回少年 2020-12-13 03:55

I have a grouped type table view and it looks pretty cool.

But, if I change the background color of the table to black, the titles becomes unclear.

Is it pos

6条回答
  •  醉酒成梦
    2020-12-13 04:35

    To use the default coordinates and the sections in TableView, with white-color font and shadow:

    -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
    {
        NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
        if (sectionTitle == nil) {
            return nil;
        }
    
        UILabel *label = [[UILabel alloc] init];
        label.frame = CGRectMake(20, 8, 320, 20);
        label.backgroundColor = [UIColor clearColor];
        label.textColor = [UIColor whiteColor];
        label.shadowColor = [UIColor grayColor];
        label.shadowOffset = CGSizeMake(-1.0, 1.0);
        label.font = [UIFont boldSystemFontOfSize:16];
        label.text = sectionTitle;
    
        UIView *view = [[UIView alloc] init];
        [view addSubview:label];
    
        return view;
    }
    

提交回复
热议问题