WMPageController

An easy solution to page controllers like NetEase News

  • 所有者: wangmchn/WMPageController
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

WMPageController 中文介绍

Platform
License
CocoaPods Version

An easy solution to page controllers like NetEase News

Overview

Change Log

See CHANGELOG for more information.

Basic use

Create an controller extends from WMPageController.There are two ways to init the WMPageController:

Init with Classes

Use the following constructor to init the controller:

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

Here are two important porperties:

classes :contains the classes of child view controllers, just like [UITableViewController class];
titles  :Each View controller's title to show in the menu view at the top of the view;

Use datasource (Recommend This Way!)

The usage is very familiar to UITableView, these are the methods need to implement:

- (NSInteger)numbersOfChildControllersInPageController:(WMPageController *)pageController;

- (__kindof UIViewController *)pageController:(WMPageController *)pageController viewControllerAtIndex:(NSInteger)index;

- (NSString *)pageController:(WMPageController *)pageController titleAtIndex:(NSInteger)index;

Just implement these datasource methods in YOUR WMPageController after initialize it.

Customize Content's Frame

It's easy for you to customize your controller as following, just implement these two datasource methods.

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForContentView:(WMScrollView *)contentView;

- (CGRect)pageController:(WMPageController *)pageController preferredFrameForMenuView:(WMMenuView *)menuView;

When you want to change the frame of contentView, you need to call -forceLayoutSubViews method. This will recall the datasource method above and re-layout subviews.
If you are interested, see viewFrameExample for more detail.

Use Storyboard / xib

1.If you init the WMPageController with child controller's class,override the -init method in WMPageController's childViewController, For example:

- (instancetype)init {
    return [self initWithNibName:@"xxxViewController" bundle:nil];
}

2.If you are using datasource, Just implement -pageController:viewControllerAtIndex: as following:

- (UIViewController *)pageController:(WMPageController *)pageController viewControllerAtIndex:(NSInteger)index {
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"WMViewController"];
    return vc;
}

See StoryboardExample for more detail.

Styles

You can easily change style by setting xxxPageController.style = WMMenuViewStyleLine.
If you want menuView to show on the navigation bar, set .showOnNavigationBar = YES;

Using CocoaPods

If you want the newest version, try 2.4.0 (This has some API modified)

pod 'WMPageController', '~> 2.4.0' 

If you perfer the old, just use 2.3.0 and it's fine.

pod 'WMPageController', '2.3.0' 

Note

  1. If you have any trouble with content controller's frame or size,just try set viewFrame property, which make you free to customize your own size.

  2. You can put every controller in WMPageController,But if you want have a UICollectionViewController in, please have an attention to UICollectionViewController's init method.
    You should override the - init to give UICollectionViewController a UICollectionViewLayout.
    Here is an example:

- (instancetype)init {
    // init layout here...
    self = [self initWithCollectionViewLayout:layout];
    if (self) {
        // insert code here...
    }
    return self;
}

License

This project is under MIT License. See LICENSE file for more information.

主要指标

概览
名称与所有者wangmchn/WMPageController
主编程语言Objective-C
编程语言Objective-C (语言数: 2)
平台
许可证MIT License
所有者活动
创建于2015-06-14 13:18:36
推送于2023-08-23 04:21:23
最后一次提交2018-07-02 15:05:12
发布数80
最新版本名称2.5.2 (发布于 )
第一版名称1.2.0 (发布于 2015-11-05 23:04:11)
用户参与
星数2.9k
关注者数69
派生数628
提交数413
已启用问题?
问题数609
打开的问题数283
拉请求数25
打开的拉请求数8
关闭的拉请求数8
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?