mport "QLPageView.h"
初始化
NSArray *vcs = @[[[TestViewController1 alloc] init], [[TestViewController2 alloc] init], [[TestViewController3 alloc] init], [[TestViewController4 alloc] init], [[TestViewController5 alloc] init], [[TestViewController6 alloc] init]]; NSArray *titles = @[@"第一页", @"第二页", @"3", @"第4444444444页", @"第5页", @"第六页"]; CGFloat y = KIsiPhoneX ? 88 : 64; //同样的页面跟换数据源的话,直接循环 QLPageView *toolView = [[QLPageView alloc] initWithFrame:CGRectMake(0, y, self.view.bounds.size.width, self.view.bounds.size.height - y) viewControllers:vcs titles:titles]; toolView.mDelegate = self; //下面这几个属性自由选择是赋值 toolView.itemNormalColor = [UIColor blackColor]; toolView.itemSelectedColor = [UIColor redColor]; toolView.hideShadow = NO; toolView.selectedIndex = 3; //这一句必须写 [toolView showInViewController:self];
遵循代理并实现代理
#pragma mark - QLPageViewDelegate- (void)selectedPageOfIndex:(NSInteger)index{ NSLog(@"selected %ld", index); }
效果图
image
不需要居中的话只需要把这里注释掉
image
写的时候分析附图,纠正一下,既然viewWillAppear每次执行,那么肯定比在
scrollowView上面横向加多个viewController这种一次性全部加载的性能要好很多!
作者:墨柒_js
链接:https://www.jianshu.com/p/7b23c068200a
點擊查看更多內容
為 TA 點贊
評論
評論
共同學習,寫下你的評論
評論加載中...
作者其他優質文章
正在加載中
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦