How to mimic UITableView#39;s UITableViewStylePlain section header style(如何模仿 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 部分标题样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何模仿 UITableView 的 UITableViewStylePlain 部分标题样式
基础教程推荐
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iOS4 创建后台定时器 2022-01-01
