【发布时间】:2012-01-23 11:54:34
【问题描述】:
我需要在 iOS 5 中更改 sectionIndexTitlesForTableView 的颜色。我在 API 中找不到任何方法来执行该任务。谁能帮帮我?
sectionIndexTitlesForTableView 表示右侧的竖条,用于显示部分的标题。
谢谢。
【问题讨论】:
我需要在 iOS 5 中更改 sectionIndexTitlesForTableView 的颜色。我在 API 中找不到任何方法来执行该任务。谁能帮帮我?
sectionIndexTitlesForTableView 表示右侧的竖条,用于显示部分的标题。
谢谢。
【问题讨论】:
转到 IB 并将文本颜色更改为白色,为我工作
//==========================================
在 Swift 中,您还可以通过以下方式以编程方式更改:
self.my_tableView.sectionIndexColor = UIColor.greenColor()
【讨论】:
以下代码是直接的解决方案。 api 可从 iOS 6 获得
[tableView setSectionIndexColor:[UIColor greenColor]];
【讨论】:
斯威夫特 3
你可以设置:
tableView.sectionIndexColor
你想要的任何颜色:
tableView.sectionIndexColor = .red
【讨论】:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
for(UIView *view in [tableView subviews])
{
if([[[view class] description] isEqualToString:@"UITableViewIndex"])
{
[view performSelector:@selector(setIndexColor:) withObject:[UIColor redColor]];
}
}
static NSString *MyIdentifier = @"MyIdentifier";
//***Table cell create
}
【讨论】:
在您的 viewDidLoad 中编写 Bellow 代码(用于 swift)
tableName.sectionIndexColor = UIColor.lightGrayColor()
【讨论】:
你也可以通过改变tableView的tintColor来改变section索引颜色。
tableView.tintColor = .red
【讨论】:
很遗憾,我认为没有记录在案的方法来自定义您的索引。
试着看看这些问答:
sectioned tableview index selection highlighting
How do I change the color of the side Alphabet in an indexed UITableView?
【讨论】: