测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | 自定义 |
发布最后发布 | 2017年3月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Niklas Fahl,Matthew York 维护。
Objective-C 版本处于测试阶段
| | | |
Funny Or Die | Alabama MVD | HEALTHFUL | Bboy Event |
Funny Or Die, Inc. | CAPS | Junaid Younus | Jazz Pixels 有限公司 |
1.2.8 发布 (2015年6月22日)
一个完全可定制且灵活的滚 页菜单控制器,由其他放在滚动视图中的视图控制器组成,允许用户通过简单点击或滑动手势切换到任何类型的视图控制器,类似于 Spotify、Windows Phone 和 Instagram 所使用的。
类似于 Spotify
类似于 Windows Phone
类似于 Instagram 的分段控制
CocoaPods
PageMenu 通过 CocoaPods 提供。**仅 Swift **!
要安装,请将以下行添加到您的 Podfile 中:
pod 'PageMenu'
Carthage
手动安装
PageMenu 所需的类文件位于本仓库根目录下的 Classes 文件夹中,如下所示:
首先,您需要创建一个视图控制器作为页面菜单的基座。这可以是一个视图控制器,其 xib 文件作为单独的文件,也可以将其 xib 文件放入故事板中。接下来,您将按照以下简单步骤进行,以便让一切运行起来。
1) 将安装部分中列出的文件添加到您的项目中
2) 在您的基座视图控制器中添加一个 CAPSPageMenu 属性
Swift
var pageMenu : CAPSPageMenu?
Objective-C
@property (nonatomic) CAPSPageMenu *pagemenu;
3) 在您的视图控制器的 viewDidLoad 函数中添加以下代码:
Swift
// Array to keep track of controllers in page menu
var controllerArray : [UIViewController] = []
// Create variables for all view controllers you want to put in the
// page menu, initialize them, and add each to the controller array.
// (Can be any UIViewController subclass)
// Make sure the title property of all view controllers is set
// Example:
var controller : UIViewController = UIViewController(nibName: "controllerNibName", bundle: nil)
controller.title = "SAMPLE TITLE"
controllerArray.append(controller)
// Customize page menu to your liking (optional) or use default settings by sending nil for 'options' in the init
// Example:
var parameters: [CAPSPageMenuOption] = [
.MenuItemSeparatorWidth(4.3),
.UseMenuLikeSegmentedControl(true),
.MenuItemSeparatorPercentageHeight(0.1)
]
// Initialize page menu with controller array, frame, and optional parameters
pageMenu = CAPSPageMenu(viewControllers: controllerArray, frame: CGRectMake(0.0, 0.0, self.view.frame.width, self.view.frame.height), pageMenuOptions: parameters)
// Lastly add page menu as subview of base view controller view
// or use pageMenu controller in you view hierachy as desired
self.view.addSubview(pageMenu!.view)
Objective-C
// Array to keep track of controllers in page menu
NSMutableArray *controllerArray = [NSMutableArray array];
// Create variables for all view controllers you want to put in the
// page menu, initialize them, and add each to the controller array.
// (Can be any UIViewController subclass)
// Make sure the title property of all view controllers is set
// Example:
UIViewController *controller = [UIViewController alloc] initWithNibname:@"controllerNibnName" bundle:nil];
controller.title = @"SAMPLE TITLE";
[controllerArray addObject:controller];
// Customize page menu to your liking (optional) or use default settings by sending nil for 'options' in the init
// Example:
NSDictionary *parameters = @{CAPSPageMenuOptionMenuItemSeparatorWidth: @(4.3),
CAPSPageMenuOptionUseMenuLikeSegmentedControl: @(YES),
CAPSPageMenuOptionMenuItemSeparatorPercentageHeight: @(0.1)
};
// Initialize page menu with controller array, frame, and optional parameters
_pageMenu = [[CAPSPageMenu alloc] initWithViewControllers:controllerArray frame:CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height) options:parameters];
// Lastly add page menu as subview of base view controller view
// or use pageMenu controller in you view hierachy as desired
[self.view addSubview:_pageMenu.view];
4) 可选 - 委托方法
要使用委托方法,首先在设置时将页面菜单的委托设置为父视图控制器
Swift
// Optional delegate
pageMenu!.delegate = self
Objective-C
// Optional delegate
_pageMenu.delegate = self;
之后,您将能够在父视图控制器内部设置以下委托方法
Swift
func willMoveToPage(controller: UIViewController, index: Int){}
func didMoveToPage(controller: UIViewController, index: Int){}
Objective-C
// Optional delegate
- (void)willMoveToPage:(UIViewController *)controller index:(NSInteger)index {}
- (void)didMoveToPage:(UIViewController *)controller index:(NSInteger)index {}
5) 现在您应该可以使用 PageMenu 了!!
有许多方法可以自定义页面菜单以满足您的需求,并且在将来还将添加更多自定义选项以确保页面菜单符合您的应用设计。所有这些都将是CAPSPageMenu中的属性,您可以从基本视图控制器中更改它们。(以下各项中给出的属性名称)
1) 颜色
页面菜单滚动视图后面的背景颜色,以融合视图控制器的背景
viewBackgroundColor (UIColor)
滚动菜单背景颜色
scrollMenuBackgroundColor (UIColor)
选择指示器颜色
selectionIndicatorColor (UIColor)
选中菜单项标签颜色
selectedMenuItemLabelColor (UIColor)
未选中菜单项标签颜色
unselectedMenuItemLabelColor (UIColor)
菜单项分割线颜色(用于分段控制风格)
menuItemSeparatorColor (UIColor)
底部菜单发丝线颜色
bottomMenuHairlineColor (UIColor)
2) 尺寸
滚动菜单高度
menuHeight (CGFloat)
滚动菜单边距(第一个和最后一个菜单项之前和之后的空隙以及项目之间的空隙)
menuMargin (CGFloat)
滚动菜单项宽度
menuItemWidth (CGFloat)
选择指示器高度
selectionIndicatorHeight (CGFloat)
3) 分段控件
将PageMenu用作分段控件
useMenuLikeSegmentedControl (Bool)
菜单项分割线宽度(以像素为单位)
menuItemSeparatorWidth (CGFloat)
菜单项分割线高度(菜单高度的百分比)
menuItemSeparatorPercentageHeight (CGFloat)
菜单项分割线有圆角
menuItemSeparatorRoundEdges (Bool)
4) 其他
菜单项标题标签字体
menuItemFont (UIFont)
底部菜单发丝线
addBottomMenuHairline (Bool)
菜单项宽度基于标题文本宽度(见演示3)
menuItemWidthBasedOnTitleTextWidth (Bool)
禁用/启用控制器滚动视图的水平反弹
enableHorizontalBounce (Bool)
隐藏/显示顶部菜单栏
hideTopMenuBar (Bool)
如果菜单项没有占满整个宽度,则在菜单中居中菜单项(目前不支持基于标题的菜单项宽度)
centerMenuItems (Bool)
在菜单项上点击时的滚动动画持续时间(以毫秒为单位)
scrollAnimationDurationOnMenuItemTap (Int)
如果您的在AppStore中的应用程序使用了这个库,请让我知道,这样我可以将您的应用程序添加到PageMenu特色应用程序列表中。
Niklas Fahl (fahlout) - iOS开发者(LinkedIn)
感谢您的贡献
1.2.7版发布(2015年6月5日)
1.2.6版发布(2015年5月26日)
1.2.5版发布(2015年4月14日)
1.2.4版发布(2015年3月24日)
1.2.3版发布(2015年2月9日)
1.2.2版发布(2015年2月9日)
1.2.1版发布(2015年2月2日)
1.2.0版本发布(2015年1月26日)
1.1.1版本发布(2015年1月16日)
1.1.0版本发布(2015年1月15日)
版权所有 © 2014 阿拉巴马大学董事会。保留所有权利。
以下条件满足的情况下,允许以源代码形式和二进制形式重新分发和使用,无论是否修改:
本软件由版权所有者和贡献者提供“原样”以及任何明确或隐含的保证,包括但不限于适销性和针对特定目的的适用性的保证。在任何情况下,版权所有者或贡献者均不对任何直接、间接、偶然、特殊、示范性或后果性损害(包括但不限于替代物品或服务的采购;使用、数据或利润的损失;或业务的中断)负责,无论这些损害是由于何种原因造成的,以及基于何种责任理论,包括疏忽或其他方式,即使已事先告知这种损害的可能性。