【发布时间】:2011-02-08 06:15:48
【问题描述】:
【问题讨论】:
标签: iphone objective-c cocoa-touch uitableview
【问题讨论】:
标签: iphone objective-c cocoa-touch uitableview
看起来标准索引视图不是可定制的。
在我的应用程序中,我刚刚创建了自定义索引视图,而不是标准视图。基本上你需要做的就是在那个视图中跟踪触摸位置并相应地滚动 UITableView。您可能还需要添加一些视觉效果 - 在触摸时更改视图的背景颜色并突出显示当前部分标题。
【讨论】:
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;
【讨论】:
Swift 版本:
tableView.sectionIndexBackgroundColor = UIColor.clearColor() //iOS7+
tableView.sectionIndexTrackingBackgroundColor = UIColor.clearColor() //iOS6+
tableView.sectionIndexColor = UIColor.redColor() //iOS6+
自定义索引视图高度(仅限UITableViewStylePlain 样式):
tableView.sectionIndexMinimumDisplayRowCount = 15
【讨论】:
tableView.tintColor = UIColor.redColor();
会为你做的
【讨论】:
实际上没有官方的 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
}()
【讨论】: