代码之家  ›  专栏  ›  技术社区  ›  sagarkothari

在iPhone应用程序的uiTableView中自定义节索引

  •  11
  • sagarkothari  · 技术社区  · 15 年前
    5 回复  |  直到 7 年前
        1
  •  12
  •   Vladimir    15 年前

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

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

        2
  •  1
  •   Emile Khattar    12 年前

    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;
    
        3
  •  1
  •   SoftDesigner    9 年前

    SWIFT版:

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

    自定义索引视图高度的步骤( UITableViewStylePlain 风格:

    tableView.sectionIndexMinimumDisplayRowCount = 15
    
        4
  •  0
  •   josliber Martin Ballet    9 年前
    tableView.tintColor = UIColor.redColor();
    

    会为你做的

        5
  •  0
  •   Tim    7 年前

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

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

    https://github.com/ReverseScale/CollectionIndexTools

    以下是CollectionIndexTools的示例片段

    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
        }()