How do I change the color of the side Alphabet in an indexed UITableView?

后端 未结 12 933
温柔的废话
温柔的废话 2020-11-27 14:03

I have a table view with an alphabetical index and am using the side alphabet to get through the list quickly. For those not familiar, that uses this:

- (NS         


        
12条回答
  •  眼角桃花
    2020-11-27 14:24

    Make a mutable array to contain the alternate title label In

    -(NSArray * )sectionIndexTitlesForTableView:(UITableView * )tableView
    

    return an array of @" " where the number of spaces between the quotes determines the width of the hi-lighted scroller. Have "sectionIndexTitlesForTableView" call an update label function. In that function remove all the labels in the array you created earlier from their superviews Then create and add however many labels are needed. Then add them to the table's superview.

    These are the lines required to place the labels in the right place.

    rect.origin.x = table.frame.origin.x+table.frame.size.width-rect.size.width-2;
    rect.origin.y = 5+table.frame.origin.y+counter *(280-rect.size.height-([customIndexLabels count]-1))/([customIndexLabels count]-1);
    if ([customIndexLabels lastObject]==thisLabel)
    {
       rect.origin.y-=10;
    }
    

    Hope that helps. It's not perfect I just don't care enough to fix it myself The main problem is that the spacing of the last label is not uniform.

提交回复
热议问题