我有一个深色背景,上面有一个UITableView
。默认情况下,节索引是半透明的,带有深色文本颜色。我想将部分索引的文本颜色更改为与我制作UITableViewCell
标题标签相同的颜色。我已经阅读了一些内容,似乎您必须对UITableView
进行子类化?我该怎么做?
从iOS 6开始,您可以这样做:
searchTable.sectionIndexColor = [UIColor blackColor];
为了解决这个问题,我在viewDidAppear中使用了以下内容:
for (UIView *subView in [self.view subviews])
{
if ([[[subView class] description] isEqualToString:@"UITableViewIndex"])
{
[subView performSelector:@selector(setIndexColor:) withObject:[UIColor whiteColor]];
}
}
由于它没有记录,因此必须通过选择器。
从iOS 6.0开始,有两种方法允许您更改部分索引的颜色以及拖动洗涤器时显示的背景。
if ([tableView respondsToSelector:@selector(setSectionIndexColor:)]) {
tableView.sectionIndexColor = ... // some color
tableView.sectionIndexTrackingBackgroundColor = ... // some other color
}
当然,这只会在设备具有 6.0+ 时执行。对于任何较旧的iOS,都不会改变。