SectionIndexView which could be highly customized, can easily be used to customize the UITableView's section index .
pod 'SectionIndexView'
SectionIndexView is easy to use, API are like UITableView.
Init SectionIndexView
.
override func viewDidLoad() {
......
indexView = SectionIndexView.init(frame:frame)
indexView.dataSource = self
indexView.delegate = self
view.addSubview(indexView)
indexView.loadData() // important
}
Conforming to protocol SectionIndexViewDataSource
.
func numberOfItemViews(in sectionIndexView: SectionIndexView) -> Int {
return indexData.count
}
func sectionIndexView(_ sectionIndexView: SectionIndexView, itemViewAt section: Int) -> SectionIndexViewItem {
let itemView = SectionIndexViewItem.init()
itemView.title = indexData[section]
return itemView
}
// when you need SectionIndexViewItemPreview
func sectionIndexView(_ sectionIndexView: SectionIndexView, itemPreviewFor section: Int) -> SectionIndexViewItemPreview {
let preview = SectionIndexViewItemPreview.init(title: indexData[section], type: .default)
return preview
}
Conforming to protocol SectionIndexViewDelegate
.
All of them are optional.
//didSelect
func sectionIndexView(_ sectionIndexView: SectionIndexView, didSelect section: Int)
//toucheMoved
func sectionIndexView(_ sectionIndexView: SectionIndexView, toucheMoved section: Int)
//toucheCancelled
func sectionIndexView(_ sectionIndexView: SectionIndexView, toucheCancelled section: Int)
Please see the demo for more details.
SectionIndexView is released under an MIT license.