WMPageController:類似網易新聞首頁效果的實現(OC)

jopen 9年前發布 | 59K 次閱讀 iOS開發 移動開發 WMPageController

WMPageController:類似網易新聞首頁效果的實現(OC)。

Overview

Default style


New style!
WMMenuViewStyleLine
And it's also remember the position now!
CHEERS!


And you can easily have this style only by one step;

pageController.menuViewStyle = WMMenuViewStyleLine;


What's New

  • If items width didn't fill the screen width,page controller will calculate width and add gap between each item automatically;
  • Page controller will remember the position, if it's a kind of scrollView controller,(that means:UITabelViewController,UICollectionViewController,or a controller you have replacedcontroller.viewtoscrollview,or you have add a scrollview as it's first subview);
  • Adjust views and frames when device's orientation changed;
  • Set the propertyitemsWidthsto have different width!Like@[@(100),@(80),@(50).....];
  • Waiting for new function...

Basic use

First Drag files in red frame to your project.
Guide

Then,create an controller that extends fromWMPageController.I recommend to use

- (instancetype)initWithViewControllerClasses:(NSArray *)classes andTheirTitles:(NSArray *)titles;

to init the controller.Here are two important porperties

classes :contains the classes of view controller, you can put obj in like [UITableViewController class];
titles  :Each View controller's title to show in the menu view at the top of the view;

To have a custom page controller,please set the properties inWMPageController,They are:titleSize,titleColor,menuHeight,pageAnimatable,menuBGColor,menuItemWidth,rememberLocation,and alsoitemsWidths.

Attention

When you are setting the title color, please use those have RGBA components,except like [UIColor blackColor],[UIColor grayColor],ect.,or USE [UIColor colorWithRed:green:blue:alpha:]to make sure the color definitely work.

Pod

pod 'WMPageController'

Note

You can put every controller inWMPageController,But if you want have aUICollectionViewControllerin, please have an attention toUICollectionViewController'sinit method.
You should override the- initto giveUICollectionViewControlleraUICollectionViewLayout. Here is an example:

- (instancetype)init{
    UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc] init];
    flow.minimumLineSpacing = 1;
    flow.minimumInteritemSpacing = .1;
    CGFloat width = [[UIScreen mainScreen] bounds].size.width / 4 - 3*0.1;
    flow.itemSize = CGSizeMake(width,width);
    self = [self initWithCollectionViewLayout:flow];
    if (self) {
        // insert code here...
    }
    return self;
}

項目主頁:http://www.baiduhome.net/lib/view/home/1436340615489

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!