tableViewIndex.png
<b>簡單修改索引顏色,在viewDidLoad中添加如下代碼即可</b>
//設(shè)置索引列文本的顏色
self.tableView.sectionIndexColor = [UIColor colorWithHexString:@"#5cd0c2"];
//設(shè)置索引背景顏色透明
if ([self.tableView respondsToSelector:@selector(setSectionIndexColor:)])
{
self.tableView.sectionIndexBackgroundColor = [UIColor clearColor];
self.tableView.sectionIndexTrackingBackgroundColor = [UIColor clearColor];
}
<b>注:如果想實(shí)現(xiàn)更棒的效果只能自定義了哈</b>
思路:點(diǎn)擊自定義索引時(shí)提供點(diǎn)擊事件滾動(dòng)到對(duì)應(yīng)區(qū)域即可贷岸,下面是系統(tǒng)的
// 點(diǎn)擊索引
-(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
// 獲取所點(diǎn)目錄對(duì)應(yīng)的indexPath值
NSIndexPath *selectIndexPath = [NSIndexPath indexPathForRow:0 inSection:index];
// 讓table滾動(dòng)到對(duì)應(yīng)的indexPath位置
[tableView scrollToRowAtIndexPath:selectIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
return index;
}
Demo地址:http://這個(gè)沒有demo??