一个简单的 iOS 分页视图。
在 CocoaPods 中可用
pod 'BSSegmentPagingView'
或
BSSegmentPagingView
文件夹复制到项目;Masonry
。#import "BSSegmentPagingView.h"
BSSegmentPagingView
的实例;实现 BSSegmentPagingViewDelegate
和 BSSegmentPagingViewDataSource
的必要方法
示例实现
#pragma - mark BSSegmentPagingViewDelegate
- (void)bsPagingView:(BSSegmentPagingView *)pagingView didScrollToPage:(NSUInteger)pageIndex {
self.segmentControl.selectedSegmentIndex = pageIndex;
}
#pragma - mark BSSegmentPagingViewDataSource
- (NSUInteger)numberOfPageInPagingView:(BSSegmentPagingView *)pagingView {
return 3;
}
- (UIView *)pageAtIndex:(NSUInteger)index {
UIView *view = [[UIView alloc] init];
switch (index) {
case 0:
view.backgroundColor = [UIColor greenColor];
break;
case 1:
{
SecondPageViewController *secondPageVC = [[SecondPageViewController alloc] init];
[self addChildViewController:secondPageVC];
[secondPageVC didMoveToParentViewController:self];
return secondPageVC.view;
}
break;
case 2:
view.backgroundColor = [UIColor blueColor];
break;
default:
break;
}
return view;
}