gpt4 book ai didi

ios - 如何模仿 UITableView 的 UITableViewStylePlain section header 样式

转载 作者:技术小花猫 更新时间:2023-10-29 10:33:49 27 4
gpt4 key购买 nike

我的应用程序在 UITableView 部分标题标题中使用了 VoiceOver 难以发音的缩写。由于我需要使这些标题可由 VoiceOver 发音,因此我需要为节标题提供 accessibilityLabel

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

模仿 UITableViewStylePlain 部分标题样式的最佳方法是什么?

更新:我很清楚如何创建自定义标题单元格。我正在寻找的是一种技术,可以准确模仿 Apple 为普通 UITableView 部分标题单元格提供的标题单元格样式的外观。

最佳答案

如果有人仍然感兴趣,我用下面的代码让它看起来非常接近(使用上面评论中的 Mark Adams 图片,但我稍微调整了它们的大小,因为我的应用程序也有横向模式):

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

关于ios - 如何模仿 UITableView 的 UITableViewStylePlain section header 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4664687/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com