BDKCollectionIndexView 2.2.2

BDKCollectionIndexView 2.2.2

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
发布最后发布2016 年 7 月

Ben Kreeger 维护。



  • Ben Kreeger

一个索引标题擦除条,适用于 UICollectionView 或作为 UITableView 提供的替代品。为集合/表格视图提供索引标题栏,类似于 UITableView 获得的几乎免费。向 @Yang 发表在 此 Stack Overflow 帖子 上的帮助表示感谢,它在这里救了我。

gif

用法

要使用 CocoaPods 参与,只需在您的 Podfile 中添加此行

pod 'BDKCollectionIndexView'

然后自然地运行 pod install。之后,创建一个 BDKCollectionIndexView 实例,并将其添加到包含您的 tableViewcollectionView(但不是 tableViewcollectionView 本身)的任何 view 中。然后为它分配 28(如果作为水平索引视图使用,则为 height)的 width 值。附加您认为合适的任何其他布局约束!

override func viewDidLoad() {
    super.viewDidLoad()

    let indexWidth = 28
    let frame = CGRect(x: collectionView.frame.size.width - indexWidth,
        y: collectionView.frame.size.height,
        width: indexWidth,
        height: collectionView.frame.size.height)
    var indexView = BDKCollectionIndexView(frame: frame, indexTitles: nil)
    indexView.autoresizingMask = .FlexibleHeight | .FlexibleLeftMargin
    indexView.addTarget(self, action: "indexViewValueChanged:", forControlEvents: .ValueChanged)
    view.addSubview(indexView)
}

func indexViewValueChanged(sender: BDKCollectionIndexView) {
    let path = NSIndexPath(forItem: 0, inSection: sender.currentIndex)
    collectionView.scrollToItemAtIndexPath(path, atScrollPosition: .Top, animated: false)
    // If you're using a collection view, bump the y-offset by a certain number of points
    // because it won't otherwise account for any section headers you may have.
    collectionView.contentOffset = CGPoint(x: collectionView.contentOffset.x,
        y: collectionView.contentOffset.y - 45.0)
}

然后,当您有了部分索引标题(而不是,您希望在索引栏上显示的标签值)时,将该数组分配给索引栏实例的 indexTitles 值。

self.indexView.indexTitles = self.resultsController.sectionIndexTitles

您可以修改 backgroundColortouchStatusBackgroundColor 属性以更改“触摸状态视图”的背景颜色,该视图在触摸视图时出现。使用 BDKCollectionIndexView 实例的 tintColor 改变文本标签的颜色。

再次感谢 @Yang 为此提供基于 此解决方案

请...

如果您在使用此项目,请给我发一条消息!我很乐意听听。您可以通过 电子邮件、在 Twitter 上或通过 鸽子 与我联系。

联系方式

贡献者