如何模仿 UITableView 的 UITableViewStylePlain 部分标题样式 [英] How to mimic UITableView's UITableViewStylePlain section header style

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

问题描述

我的应用程序在 UITableView 部分标题标题中使用了 VoiceOver 难以发音的缩写.因为我需要让 VoiceOver 能够发音这些标题,所以我需要给部分标题标题一个 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.

似乎这样做的唯一方法是绘制自定义部分标题单元格.我想模仿 Apple UIKit 为这些自定义部分标题提供的标准样式,但我不确定如何模拟 Apple 对该元素的详细外观.

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?

更新:我很清楚如何创建自定义标题单元格.我正在寻找的是一种完全模仿 Apple 为普通 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 部分标题样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆