要运行示例项目,请首先克隆仓库,然后从 Example 目录中运行 pod install
。
YFPageView 通过 CocoaPods 提供。要安装它,只需在 Podfile 中添加以下行
pod "YFPageView"
1. 引用头文件 #import "YFPageViewController.h"
2.
//创建控制器,并添加为当前控制器的子控制器
self.pageViewController = [[YFPageViewController alloc] init];
[self addChildViewController:self.pageViewController];
//设置view的frame
self.pageViewController.view.frame = self.view.bounds;
//设置segmentView的frame
self.pageViewController.segmentView.frame = CGRectMake(0, 0, yfWidth, 44);
[self.view addSubview:self.pageViewController.view];
//设置segment的参数
///链式编程调用,类似masonry
[self.pageViewController.segmentView updateConfig:^(YFSegmentViewConfig *config) {
//链式设置属性
config.normalColor([UIColor lightGrayColor]).seletcedColor([UIColor redColor]).line([UIColor redColor]).font(14).viewBackColor([UIColor whiteColor]);
//普通设置属性
// config.titleButtonColorNormal = [UIColor lightGrayColor];
// config.titleButtonColorSeletced = [UIColor orangeColor];
// config.lineColor = [UIColor orangeColor];
// config.buttonfont = [UIFont systemFontOfSize:14];
}];
//设置每个item的控制器
NSMutableArray * vcArray = [NSMutableArray array];
for (int i = 0; i < 5; i ++) {
UIViewController * vc = [UIViewController new];
vc.view.backgroundColor = RandomColor;
[vcArray addObject:vc];
}
//设置item的标题
NSArray * titleArray = @[@"你啊后",@"再见",@"考试",@"回家",@"总决赛"];
//设置控件
[self.pageViewController setContentWithTitles:titleArray vcs:vcArray];
YFPageView 在 MIT 许可下提供。有关更多信息,请参阅 LICENSE 文件。