WMPageController 中文介绍
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; ``` ## 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
anditemsMargins
to custom margin between each item,viewFrame
to custom controller.view's frame. - Add
values
andkeys
properties which can help pass values to childControllers throughKVC
. - 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
,,and also rememberLocation
itemsWidths
.
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
特性
- 增加了缓存机制,对加载过的控制器进行缓存,当内存过高时自动清理缓存。
- 可通过
itemMargin
和itemsMargins
来定制顶部标题的间距,通过viewFrame
来定制子控制器的frame
属性。 - 通过设置
values
和keys
向子控制器传值。(内部利用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
.
使用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
文件。