Customising the font/background colour of index/section bar in UITableView

前端 未结 3 1041
轮回少年
轮回少年 2021-01-01 14:29

I\'ve read in another thread on SO that you can adjust the font or background colour of the index bar (that is the A-Z # scrollbar) in a UITableView adding a CALayer. My app

相关标签:
3条回答
  • 2021-01-01 14:56

    For Swift 3.1:

     self.tblViewForContacts.sectionIndexTrackingBackgroundColor = self.view.backgroundColor
     self.tblViewForContacts.sectionIndexBackgroundColor = self.view.backgroundColor
    
    0 讨论(0)
  • 2021-01-01 14:57

    Here is code for swift 2+

    self.tableView.sectionIndexTrackingBackgroundColor = CustomColor
    // background color while the index view is being touched
    self.tableView.sectionIndexBackgroundColor = CustomColor
    // title/text color of index items 
    self.tableView.sectionIndexColor = CustomColor
    
    0 讨论(0)
  • 2021-01-01 15:08

    As of iOS 6.0 there are two methods that allow you to change the color of the section indexes and the background shown when you drag along the section indexes.

    if ([tableView respondsToSelector:@selector(setSectionIndexColor:)]) {
        tableView.sectionIndexColor = ... // some color
        tableView.sectionIndexTrackingBackgroundColor = ... // some other color
    }
    

    Of course this will only execute if the device has 6.0 or later. Under iOS 5.x, nothing will change.

    0 讨论(0)
提交回复
热议问题