(转)tableview的索引设置

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 @ 2018-09-12 14:27  红凉梦  阅读(285)  评论(0)    收藏  举报