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