手记

MG--Swift3.0之仿写酷狗音乐的索引

  • 首先来看看酷狗的截图效果


  • 系统提供的API:

@available(iOS 3.0, *)
open func reloadSectionIndexTitles()  // reloads the index bar.
// 重新刷新右边文字

@available(iOS 6.0, *)
open var sectionIndexColor: UIColor? // color used for text of the section index         
// 右边文字的颜色

@available(iOS 7.0, *)
open var sectionIndexBackgroundColor: UIColor? // the background color of the section index while not being touched
// 设置右边的View背景颜色

@available(iOS 2.0, *)
optional public func sectionIndexTitles(for tableView: UITableView) -> [String]? // return list of section titles to display in section index view (e.g. "ABCD...Z#")
// 返回?右边的显示文字 (是一个数组)

@available(iOS 2.0, *)
optional public func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int // tell table which section corresponds to section title/index (e.g. "B",1))
// 设置选中右边的某个文字时的方法,参数1是tableVie,参数2是选中的文字,参数3是选中的文字对应数组中的索引 

  • 自定义一个MGIndexView代替系统的

    • 仿写效果:

      • 仿写初衷:就是中间的提示文字,系统自带的没有这个效果。就是说当触摸点离开右边字母索引条的时候,没有提供API接口给我们,告诉我们什么时候该让中间的提示Label消失。而且系统自带的索引选中的时候不能设置选中的颜色,也没有提供API接口给我们。
    • Demo链接: https://pan.baidu.com/s/1o8a1voI 密码: pbdd



  • 有细心的小伙伴说:“UITableView滚动的时候,右边相应的索引没有跟着改变”?,于是加了下班,有了这个效果


  • 扩展

    • 简单DES加密:







  • 轻轻点击,关注我


0人推荐
随时随地看视频
慕课网APP