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];// 设置默认时,索引的背景颜色


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM