Code Monkey home page Code Monkey logo

wmpagecontroller's Introduction

WMPageController 中文介绍

Platform License CocoaPods Version

An easy solution to page controllers like NetEase News

Overview




And you can easily change styles by setting `menuViewStyle` property: ```objective-c pageController.menuViewStyle = WMMenuViewStyleLine; ``` If you want `menuView` to show on the navigation bar, set `showOnNavigationBar = YES`;

Swift Version

Click here: https://github.com/wangmchn/WMPageController-Swift

What's New

  • Now page controller has a cache policy and scroll much more fluently!
  • Add itemMargin and itemsMargins to custom margin between each item, viewFrame to custom controller.view's frame.
  • Add values and keys properties which can help pass values to childControllers through KVC.
  • If items width didn't fill the screen width, WMPageController will calculate width and add gap between each item automatically;
  • Adjust views and frames when device's orientation changed;
  • Set the property itemsWidths to have Different Width! Like @[@(100),@(80),@(50).....];
  • Can reload data like NetEase News.

Basic use

First Drag files in red frame to your project.

Then,create an controller that extends from WMPageController.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 in WMPageController ,They are: titleSize, titleColor, menuHeight, pageAnimatable, menuBGColor, menuItemWidth,rememberLocation,and also itemsWidths.

Use Storyboard / xib

Override -init method in childViewController, For example:

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

Pod

pod 'WMPageController'

Note

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.

中文介绍

WMPageController是一个方便形成如同网易新闻首页,控制器滑动翻页效果的控制器。(原谅我拙略的英文)

Swift 实现

戳这里: https://github.com/wangmchn/WMPageController-Swift

特性

  • 增加了缓存机制,对加载过的控制器进行缓存,当内存过高时自动清理缓存。
  • 可通过itemMarginitemsMargins来定制顶部标题的间距,通过viewFrame来定制子控制器的frame属性。
  • 通过设置valueskeys向子控制器传值。(内部利用KVC实现)
  • 当标题宽度之和不足宽度时,自动计算并为顶部item添加间隙。
  • 适配横屏,当设备旋转时自动调整frame
  • 可通过设置itemsWidths属性来设置不同的标题宽度,例如 @[@(100),@(80),@(50).....];
  • 增加了reload功能,可以像网易新闻那样重新更新标题和控制器。

使用

首先,把下面红框里的内容拖入项目。

然后,创建一个控制器继承自WMPageController,并使用以下方法初始化该控制器

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

其中,Classes是要传人显示的控制器的类型,比如[UITableViewController class], titles是要显示的控制对应的标题。 如要定制WMPageController的外观,可通过设置如下属性: titleSize, titleColor, menuHeight, pageAnimatable, menuBGColor, menuItemWidth,rememberLocation,以及 itemsWidths.

使用 Storyboard / xib

重写子控制器的 -init 方法,例如:

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

使用Pod管理

pod 'WMPageController'

要点

如果需要传入 UICollectionViewController, 需要重写 - init 方法,来为UICollectionViewController提供一个 UICollectionViewLayout。 方式如下:

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

许可

该项目使用 MIT 许可证,详情见 LICENSE 文件。

wmpagecontroller's People

Contributors

wangmchn avatar codwam avatar chengxianghe avatar jeeliu avatar litt1e-p avatar

Watchers

jiangrenju avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.