玩转TableView的索引

tableViewIndex.png

<b>简单修改索引颜色,在viewDidLoad中添加如下代码即可</b>

    //设置索引列文本的颜色
     self.tableView.sectionIndexColor = [UIColor colorWithHexString:@"#5cd0c2"];
    
    //设置索引背景颜色透明
    if ([self.tableView respondsToSelector:@selector(setSectionIndexColor:)])
    {
        self.tableView.sectionIndexBackgroundColor = [UIColor clearColor];
        self.tableView.sectionIndexTrackingBackgroundColor = [UIColor clearColor];
    }

<b>注:如果想实现更棒的效果只能自定义了哈</b>

思路:点击自定义索引时提供点击事件滚动到对应区域即可,下面是系统的
// 点击索引
-(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
    // 获取所点目录对应的indexPath值
    NSIndexPath *selectIndexPath = [NSIndexPath indexPathForRow:0 inSection:index];
    // 让table滚动到对应的indexPath位置
    [tableView scrollToRowAtIndexPath:selectIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
    return index;
}

Demo地址:http://这个没有demo😄

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容