# SectionIndexView
**Repository Path**: insyangming/SectionIndexView
## Basic Information
- **Project Name**: SectionIndexView
- **Description**: 3rwerwerwer
- **Primary Language**: Swift
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2023-06-05
- **Last Updated**: 2023-06-05
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
## Overview
| default | custom | image |
| ------ | ------ | ------ |
 |  | 
## Installation
### CocoaPods
```
pod 'SectionIndexView'
```
#### Swift Package Manager
- File > Swift Packages > Add Package Dependency
`https://github.com/0xcj/SectionIndexView.git`
- Select "Up to Next Major" with "3.0.0"
### Manual
Drop the swift files inside of [SectionIndexViewDemo/SectionIndexView](https://github.com/0xcj/SectionIndexView/tree/master/SectionIndexViewDemo/SectionIndexView) into your project.
## Usage
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
```objc
- (void)viewDidLoad {
[super viewDidLoad];
......
NSMutableArray*> *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]];
}
```
## Attention
In order to assure `SectionIndexView` has correct scrolling when your navigationBar not hidden and UITableView use ` contentInsetAdjustmentBehavior` or ` automaticallyAdjustsScrollViewInsets` to adjust content. Set [adjustedContentInset](https://github.com/0xcj/SectionIndexView/blob/master/SectionIndexViewDemo/SectionIndexView/UITableView%2BSectionIndexView.swift) value equal to UITableView’s adjustment content inset
```swift
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)
}
```
If you want to control the UITableView and SectionIndexView manually,you can use it like this. [There is an example.](https://github.com/0xcj/SectionIndexView/blob/master/SectionIndexViewDemo/SectionIndexViewDemo/CusViewController.swift)
```swift
override func viewDidLoad() {
......
let indexView = SectionIndexView.init(frame: frame)
indexView.delegate = self
indexView.dataSource = self
self.view.addSubview(indexView)
}
```
Please see the demo for more details.
## License
All source code is licensed under the [License](https://github.com/0xcj/SectionIndexView/blob/master/LICENSE)