【问题标题】:Customizing Section indexes in UITableView in iphone application在 iphone 应用程序中自定义 UITableView 中的部分索引
【发布时间】:2011-02-08 06:15:48
【问题描述】:
  • 是否有人尝试自定义 UITableView 中显示的默认部分索引。
  • 我想修改 UITableView SectionIndex 的外观。
  • 是否可以自定义?
  • 是否有任何可用的委托方法?
  • 我应该使用哪些委托方法 - 如果上述问题的答案是肯定的?

【问题讨论】:

    标签: iphone objective-c cocoa-touch uitableview


    【解决方案1】:

    看起来标准索引视图不是可定制的。

    在我的应用程序中,我刚刚创建了自定义索引视图,而不是标准视图。基本上你需要做的就是在那个视图中跟踪触摸位置并相应地滚动 UITableView。您可能还需要添加一些视觉效果 - 在触摸时更改视图的背景颜色并突出显示当前部分标题。

    【讨论】:

    • 您好,能否提供您创建的索引视图的代码?
    【解决方案2】:

    https://github.com/Hyabusa/CMIndexBar

    使用 Hyabusa 的这个插件。 允许设置颜色的 UITableView 索引的简单替换

    CMIndexBar *indexBar = [[CMIndexBar alloc] initWithFrame:CGRectMake(self.view.frame.size.width-35, 10.0, 28.0, self.view.frame.size.height-20)];
    [indexBar setIndexes:[NSMutableArray arrayWithObjects:@"A",@"B",@"C",@"D",@"E",@"F",@"G", nil]];
    [self.view addSubview:indexBar];
    [indexBar release];
    

    委托

    - (void)indexSelectionDidChange:(CMIndexBar *)IndexBar:(int)index:(NSString*)title;
    

    【讨论】:

    • 是否可以将 UITableViewIndexSearch 图标添加到 CMIndexBar?
    【解决方案3】:

    Swift 版本:

    tableView.sectionIndexBackgroundColor = UIColor.clearColor() //iOS7+
    tableView.sectionIndexTrackingBackgroundColor = UIColor.clearColor() //iOS6+
    tableView.sectionIndexColor = UIColor.redColor() //iOS6+
    

    自定义索引视图高度(仅限UITableViewStylePlain 样式):

    tableView.sectionIndexMinimumDisplayRowCount = 15
    

    【讨论】:

      【解决方案4】:
      tableView.tintColor = UIColor.redColor();
      

      会为你做的

      【讨论】:

        【解决方案5】:

        实际上没有官方的 Apple 可以做到这一点。如果您这样做,Apple 可能会拒绝您的应用程序。如果您只想自定义 indexBar,那么下面的库可能会对您有所帮助。

        您可以使用自定义库 CollectionIndexTools by Swift(iOS 8+),您可以自定义。

        https://github.com/ReverseScale/CollectionIndexTools

        这是 CollectionIndexTools 的示例 sn-p

        lazy var collectionViewIndex: CollectionViewIndex = {
                let collectionViewIndex = CollectionViewIndex()
                collectionViewIndex.indexTitles = ["c", "v", "t", "m", "n", "w", "e", "r", "t", "y", "u", "i", "o", "p", "h", "d", "c", "b", "q"]
                collectionViewIndex.addTarget(self, action: #selector(FakeCollectionViewController.selectedIndexDidChange(_:)), for: .valueChanged)
                collectionViewIndex.translatesAutoresizingMaskIntoConstraints = false
                return collectionViewIndex
            }()
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-01-29
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多