简体   繁体   English

如何为UITableView的节索引设置色调?

[英]How to set a tint color for the section index of a UITableView?

有没有办法自定义UITableView的字母部分索引的灰色?

Since iOS 6.0 it's actually possible to customize the tint color for the section index. 从iOS 6.0开始,实际上可以自定义节索引的色调颜色。 The relevant properties are: sectionIndexColor and sectionIndexTrackingBackgroundColor . 相关属性是: sectionIndexColorsectionIndexTrackingBackgroundColor

iOS 7 added sectionIndexBackgroundColor which specifies the background color for the section index while not being touched. iOS 7添加了sectionIndexBackgroundColor ,它指定了触摸sectionIndexBackgroundColor索引的背景颜色。

It's maybe a bit late but as I had to deal with this problem with iOS 7 I might help you. 这可能有点晚了,但由于我不得不用iOS 7处理这个问题,我可能会帮到你。

From iOS 7 there is a new method called : 从iOS 7开始,有一种新方法叫做:

@property(nonatomic, retain) UIColor *sectionIndexColor

Now you can set the color to use for the background of the table view's section index while not being touched. 现在,您可以设置颜色,以便在未触摸时用于表视图的截面索引的背景。

As a proper code to use with iOS 6 and 7 you could : 作为适用于iOS 6和7的正确代码,您可以:

self.friendsTableView.sectionIndexTrackingBackgroundColor = [UIColor aColor]; // background color while the index view is being touched
if ([self.friendsTableView respondsToSelector:@selector(sectionIndexBackgroundColor)])
    self.friendsTableView.sectionIndexBackgroundColor = [UIColor aColor]; // background color while the index view is NOT touched at all

你应该使用UITableView的外观代理来设置这些:

[UITableView appearance].sectionIndexColor = [UIColor myTintColor];

简而言之:你可以更改fontsize和完整的backround(不是圆形的)更多是不可能的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM