2012-01-23 57 views

回答

2
- (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 

} 
+0

這似乎有點...哈克... – CW0007007

+0

你可以參考這個: http://stackoverflow.com/a/30803486/1517506 – Parthpatel1105

21

轉到IB和更改文本顏色爲白色,工作對我來說enter image description here

// =========================================

而且在斯威夫特,你還可以通過編程方式改變:

self.my_tableView.sectionIndexColor = UIColor.greenColor() 
+0

是的,這也適用於我。 –

+1

這也適用於我 - 這應該是正確的答案。 – lehn0058

+0

這應該是正確的答案 –

11

下面的代碼是直的解決方案。 API可從iOS 6的

[tableView setSectionIndexColor:[UIColor greenColor]]; 
2

寫婁代碼在viewDidLoad中(對於SWIFT)

tableName.sectionIndexColor = UIColor.lightGrayColor()

3

夫特2.0

下面的代碼行將更改表視圖上的部分索引的字體顏色。我附上了執行結果的截圖。

self.tblYourTableView.sectionIndexColor = UIColor.redColor() 

enter image description here

0

斯威夫特3

你可以設置:

tableView.sectionIndexColor 

到任何顏色你想要一個像:

tableView.sectionIndexColor = .red