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 部分标题样式


- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01