How to mimic UITableView's UITableViewStylePlain section header style

前端 未结 4 1691
孤街浪徒
孤街浪徒 2020-12-25 09:18

My application uses abbreviations in UITableView section header titles that are hard for VoiceOver to pronounce. As I need to make these titles pronounceable by

4条回答
  •  感动是毒
    2020-12-25 09:34

    If anyone is still interested, I've got it looking pretty damn close with the following code (using Mark Adams images from the comment above, but I resized them slightly as my app also has landscape mode):

    - (UIView *)tableView:(UITableView *)tbl viewForHeaderInSection:(NSInteger)section
    {
        UIView* sectionHead = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tbl.bounds.size.width, 18)];
        sectionHead.backgroundColor = [UIColor colorWithWhite:0 alpha:0];
        sectionHead.userInteractionEnabled = YES;
        sectionHead.tag = section;
    
        UIImageView *headerImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"PlainTableViewSectionHeader.png"]];
        headerImage.contentMode = UIViewContentModeScaleAspectFit;
    
        [sectionHead addSubview:headerImage];
        [headerImage release];
    
        UILabel *sectionText = [[UILabel alloc] initWithFrame:CGRectMake(10, 2, tbl.bounds.size.width - 10, 18)];
        sectionText.text = text;
        sectionText.backgroundColor = [UIColor clearColor];
        sectionText.textColor = [UIColor whiteColor];
        sectionText.shadowColor = [UIColor darkGrayColor];
        sectionText.shadowOffset = CGSizeMake(0,1);
        sectionText.font = [UIFont boldSystemFontOfSize:18];
    
        [sectionHead addSubview:sectionText];
        [sectionText release];
    
        return [sectionHead autorelease];
    }
    

提交回复
热议问题