SectionIndexView 3.0.0

SectionIndexView 3.0.0

ChenJian 维护。



  • ChenJian

概览

默认 自定义 图像
default custom image

安装

CocoaPods

pod 'SectionIndexView'

Swift 包管理器

  • 文件 > Swift 包 > 添加包依赖 https://github.com/0xcj/SectionIndexView.git
  • 选择“更新到下一个主要版本”,用“3.0.0”

手动

SectionIndexViewDemo/SectionIndexView 中的 swift 文件拖放到您的项目中。

使用方法

Swift

override func viewDidLoad() {
    ......
    let titles = ["A","B","C","D","E","F","G"]
    let items = titles.compactMap { (title) -> SectionIndexViewItem? in
            let item = SectionIndexViewItemView.init()
            item.title = title
            item.indicator = SectionIndexViewItemIndicator.init(title: title)
            return item
        }
    self.tableView.sectionIndexView(items: items)
}

Objective-C

- (void)viewDidLoad {
    [super viewDidLoad];
    ......
    NSMutableArray<UIView<SectionIndexViewItem>*> *items = [[NSMutableArray alloc]init];
    NSArray *titles = @[@"A",@"B",@"C",@"D",@"E",@"F",@"G"];
    for (NSString *title in titles) {
        SectionIndexViewItemView *item = [[SectionIndexViewItemView alloc] init];
        item.title = title
        item.indicator = [[SectionIndexViewItemIndicator alloc]initWithTitle:title];
        [items addObject:item];
    }
    [self.tableView sectionIndexViewWithItems:[NSArray arrayWithArray:items]];
}

注意事项

为了确保在使用NavigationBar未隐藏且UITableView使用 contentInsetAdjustmentBehaviorautomaticallyAdjustsScrollViewInsets 来调整内容时,SectionIndexView 可以正确滚动,请将 adjustedContentInset 的值设置为UITableView调整内容内边距值。

override func viewDidLoad() {
    ......
    let navigationBarHeight = self.navigationController.navigationBar.frame.height
    let statusBarHeight = UIApplication.shared.statusBarFrame.size.height
    let frame = CGRect.init(x: 0, y: 0, width: width, height: height)
    let tableView = UITableView.init(frame: frame, style: .plain)
    let configuration = SectionIndexViewConfiguration.init()
    configuration.adjustedContentInset = statusBarHeight + navigationBarHeight
    tableView.sectionIndexView(items: items, configuration: configuration)
}

如果您想手动控制UITableView和SectionIndexView,可以使用如下方式。有关示例,请参阅 这里

override func viewDidLoad() {
    ......
    let indexView = SectionIndexView.init(frame: frame)
    indexView.delegate = self
    indexView.dataSource = self
    self.view.addSubview(indexView)
}

请查看示例以获取更多详细信息。

许可证

所有源代码均受 许可证 保护。