WKCPageViewController滑动条控制器

原理

1.滚动条自定义视图.
2.相应的控制器UIPageViewController.

使用

1.引入库
pod 'WKCPageViewController'
#import

  1. 初始化控制器
- (WKCPageViewController *)pageController
{
if (!_pageController) {
_pageController = [[WKCPageViewController alloc] init];
_pageController.delegate = self;
_pageController.dataSurce = self;
_pageController.selectionListHeight = 100; //滑动条高度
//        _pageController.selectionListBackgroundColor = UIColor.yellowColor; //滑动条背景色
_pageController.selectionListInserts = UIEdgeInsetsMake(0, 20, 0, 20); //滑动条嵌入量
_pageController.selectionListSpacing = 15; //滑动条item间距
_pageController.selectionListItemSize = CGSizeMake(100, 100); //滑动条item大小
_pageController.controllerSpacing = 5; //控制器间距
[_pageController setCurrentIndex:2 animated:YES]; //初始坐标
}
return _pageController;
}
  1. 添加到当前控制器.
[self addChildViewController:self.pageController];
[self.view addSubview:self.pageController.view];
  1. 代理回调
// 总个数
- (NSInteger)numberOfItems
{
return 5;
}

// 滑动条普通状态视图
- (UIView *)WKCPageViewController:(WKCPageViewController *)controller selectionListViewAtIndex:(NSInteger)index
{
UIView *view = [UIView new];
view.backgroundColor = UIColor.yellowColor;
return view;
}

// 滑动条选中状态视图
- (UIView *)WKCPageViewController:(WKCPageViewController *)controller selectionListSelectedViewAtSelectedIndex:(NSInteger)selectedIndex
{
UIView *view = [UIView new];
view.backgroundColor = UIColor.redColor;
return view;
}

// 建相应的控制器
- (UIViewController *)WKCPageViewController:(WKCPageViewController *)controller viewControllerAtIndex:(NSInteger)index
{
UIViewController *vc = [[UIViewController alloc] init];
if (index == 0) {
vc.view.backgroundColor = UIColor.blueColor;
}else if (index == 1) {
vc.view.backgroundColor = UIColor.brownColor;
}else if (index == 2) {
vc.view.backgroundColor = UIColor.redColor;
}else if (index == 3) {
vc.view.backgroundColor = UIColor.greenColor;
}else if (index == 4) {
vc.view.backgroundColor = UIColor.yellowColor;
}
return vc;
}

// 坐标变化时回调
- (void)WKCPageViewController:(WKCPageViewController *)controller currentIndexChanged:(NSInteger)index
{
NSLog(@"当前坐标: %ld",index);
}

如上,就已设置完成.界面及滑动条的初始化和赋值再各自操作即可.


展示图.gif

如有bug或问题,请私信.github地址.

你可能感兴趣的:(WKCPageViewController滑动条控制器)