UITableView titleForHeaderInSection shows all caps

前端 未结 14 952
孤独总比滥情好
孤独总比滥情好 2021-01-30 16:28

I am using titleForHeaderInSection to show a header for a UITableView section. It worked fine with the iOS6 SDK, but the iOS7 SDK shows the header in all CAPS.

I guess

14条回答
  •  终归单人心
    2021-01-30 17:17

    Thanks @Animal451. This is more generic solution that would work with any type of header string.

    // We need to return the actual text so the header height gets correctly calculated
    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
    {
        return self.headerString;
    }
    
    - (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
    {
        UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
        [header.textLabel setText:self.headerString];       //String in the header becomes uppercase. Workaround to avoid that.
    
    }
    

    To avoid duplication the header string can be declared anywhere else. I have done it in the -viewDidLoad method.

提交回复
热议问题