QLPageViewController,翻頁滾動,類頭條滑動,適合做新聞媒體或者訂單類的頁面
ofollow,noindex">github地址
(宣告:此工具在寫的時候借鑑了別人的方法比如顏色漸變等,具體作者不詳)
使用非常簡單,把demo下載下來之後,把“QLPageViewControllerTool”資料夾拖入你的工程。
在使用介面匯入
import "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這種一次性全部載入的效能要好很多!

image