[Beta] 简单顶部菜单,带有选中指示器,基于 ICViewPager 风格。
在你的控制器中导入此内容
#import "JJTopMenuViewController.h"
在你的控制器中添加一个 [private] strong 属性
@interface MyViewController ()
@property (nonatomic, strong) JJTopMenuViewController *menuVC;
@end
然后在 viewDidLoad 中实例化 JJTopMenuViewController
self.menuVC = [[JJTopMenuViewController alloc] initWithMenuItems:@[ [JJMenuItem initWithTitle:@"item 1" image:[UIImage imageNamed:@"forkandknife"] badgeValue:nil], [JJMenuItem initWithTitle:@"item 2" image:[UIImage imageNamed:@"pinetree"] badgeValue:nil]] selectedItemColor:[UIColor redColor] selectedItemTextColor:[UIColor grayColor] itemTextColor:[UIColor blueColor]];
这里,你可以设置菜单项(目前你可以设置标题和图像,badgeValue 还未准备好)和属性
selectedItemColor // The color of the indicator line for the selected item
selectedItemTextColor // The color of the text for the selected item
itemTextColor // The color of the normal state of the items
menuPosition //The position of the indicator line for the selected item (JJMenuPositionTop/JJMenuPositionBottom)
TODO: Add custom font, background and alignment
之后,为 JJTopMenuViewController 中视图的框架进行布局特定设置,并将其添加到父视图中
self.menuVC.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, 60);
[self.view addSubview:self.menuVC.view];
设置委托以处理菜单项选择
self.menuVC.delegate = self;
协议中目前唯一可用的方法是 didSelectMenuItemAtIndex
-(void)topMenu:(JJTopMenuViewController *)menu didSelectMenuItemAtIndex:(NSUInteger)index;
这就是了。非常欢迎您的反馈!
版权 MIT 许可证(MIT)
版权所有 © 2014 Jhon Jaiver López
特此允许任何获得本软件及其关联文档副本(“软件”)的个人免费处理该软件,包括但不限于使用、复制、修改、合并、发布、分发、特许经营和/或出售软件副本,并允许向提供软件的个人提供这样做,前提是本版权声明和许可声明应包含在所有副本或主要部分中。
上所述的版权声明和本许可声明应包含在软件的所有副本或主要部分中。
软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性、适用于特定目的和侵权不保证。在任何情况下,作者或版权持有人均不对任何要求、损害或其他责任负责,无论是在合同、侵权或任何其他行为中,无论是由于软件或其使用或其他原因引起的软件或其使用或其他。