View的UITableViewStylePlain部分标题样式

View的UITableViewStylePlain部分标题样式

本文介绍了如何模仿UITableView的UITableViewStylePlain部分标题样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序在 UITableView 部分标题中使用了很难使VoiceOver发音的缩写。由于我需要使这些标题由VoiceOver发音,我需要给节头部标题a accessibilityLabel

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 VoiceOver, I need to give the section header title a accessibilityLabel.

似乎唯一的方法是绘制一个自定义的section header cell。我想模仿标准的Apple UIKit为这些自定义节标题提供的样式,但我不知道如何模仿苹果的这个元素的详细外观。

It seems that the only way to do this is to draw a custom section header cell. I would like to mimic the standard Apple UIKit provided style for these custom section headers but I am uncertain on how to emulate Apple's detailed look of this element.

什么是最好的方法来模仿 UITableViewStylePlain 节标题样式?

What is the best approach to mimic the UITableViewStylePlain section header style?

更新:如何创建自定义标题单元格。我正在寻找的是一种技术,以模拟纯粹的UITableView节标题单元格苹果提供的标题单元格样式的外观。

Update: I am well aware how to create a custom header cell. What I am looking for is a technique to mimic exactly the look of the header cell style as provided by Apple for the plain UITableView section header cells.

推荐答案

如果任何人仍然感兴趣,我有它看起来很漂亮的接近下面的代码(使用Mark Adams图像从上面的评论,但我调整他们略微,因为我的应用程序也有横向模式):

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];
}

这篇关于如何模仿UITableView的UITableViewStylePlain部分标题样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-04 22:40