ios tableview的索引条 sectionIndex

1.感觉tableview的索引条将表视图往左边挤了一点?别担心,只是颜色问题。只要如此设置即可

 

    //索引条背景的颜色(清空颜色就不会感觉索引条将tableview往左边挤)

        [_tableView setSectionIndexBackgroundColor:[UIColor clearColor]];

        //索引条文字的颜色

        [_tableView setSectionIndexColor:[UIColor darkGrayColor]];

 

 

2.主要是实现下面四个方法:

//返回section中的row

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

//返回每个索引的内容

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

//返回索引数组

-(NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView

//响应点击索引时的委托方法

-(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index;

 

//索引的相关属性设置如下:

 _myTableView.sectionIndexColor = [UIColor blueColor];//设置默认时索引值颜色

 _myTableView.sectionIndexTrackingBackgroundColor = [UIColor grayColor];//设置选中时,索引背景颜色

 _myTableView.sectionIndexBackgroundColor = [UIColorc learColor];// 设置默认时,索引的背景颜色

posted @ 2017-07-01 11:27  justqi  阅读(8633)  评论(0编辑  收藏  举报