创建HomeViewController并作为导航根视图
//根视图控制器
#import "HomeViewController.h"
//自己创建的c
#import "MenuViewController.h"
//导入FF的头
#import "FFDropDownMenuView.h"
@interface HomeViewController ()<FFDropDownMenuViewDelegate>
/** 下拉菜单 */
@property (nonatomic, strong) FFDropDownMenuView *dropdownMenu;
@end
@implementation HomeViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
/** 初始化下拉菜单 */
[self setupDropDownMenu];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(showDropDownMenu)];
}
/** 初始化下拉菜单 */
- (void)setupDropDownMenu {
NSArray *modelsArray = [self getMenuModelsArray];
self.dropdownMenu = [FFDropDownMenuView ff_DefaultStyleDropDownMenuWithMenuModelsArray:modelsArray menuWidth:FFDefaultFloat eachItemHeight:FFDefaultFloat menuRightMargin:FFDefaultFloat triangleRightMargin:FFDefaultFloat];
//如果有需要,可以设置代理(非必须)
self.dropdownMenu.delegate = self;
self.dropdownMenu.ifShouldScroll = NO;
[self.dropdownMenu setup];
}
/** 获取菜单模型数组 */
- (NSArray *)getMenuModelsArray {
__weak typeof(self) weakSelf = self;
//菜单模型0
FFDropDownMenuModel *menuModel0 = [FFDropDownMenuModel ff_DropDownMenuModelWithMenuItemTitle:@"QQ" menuItemIconName:@"menu2" menuBlock:^{
MenuViewController *vc = [MenuViewController new];
vc.navigationItem.title = @"QQ";
[weakSelf.navigationController pushViewController:vc animated:YES];
}];
//菜单模型1
FFDropDownMenuModel *menuModel1 = [FFDropDownMenuModel ff_DropDownMenuModelWithMenuItemTitle:@"Line" menuItemIconName:@"menu1" menuBlock:^{
MenuViewController *vc = [MenuViewController new];
vc.navigationItem.title = @"Line";
[weakSelf.navigationController pushViewController:vc animated:YES];
}];
//菜单模型2
FFDropDownMenuModel *menuModel2 = [FFDropDownMenuModel ff_DropDownMenuModelWithMenuItemTitle:@"Twitter" menuItemIconName:@"menu0" menuBlock:^{
MenuViewController *vc = [MenuViewController new];
vc.navigationItem.title = @"Twitter";
[weakSelf.navigationController pushViewController:vc animated:YES];
}];
//菜单模型3
FFDropDownMenuModel *menuModel3 = [FFDropDownMenuModel ff_DropDownMenuModelWithMenuItemTitle:@"QZone" menuItemIconName:@"menu3" menuBlock:^{
MenuViewController *vc = [MenuViewController new];
vc.navigationItem.title = @"QZone";
[weakSelf.navigationController pushViewController:vc animated:YES];
}];
//菜单模型4
FFDropDownMenuModel *menuModel4 = [FFDropDownMenuModel ff_DropDownMenuModelWithMenuItemTitle:@"WeChat" menuItemIconName:@"menu4" menuBlock:^{
MenuViewController *vc = [MenuViewController new];
vc.navigationItem.title = @"WeChat";
[weakSelf.navigationController pushViewController:vc animated:YES];
}];
//菜单模型5
FFDropDownMenuModel *menuModel5 = [FFDropDownMenuModel ff_DropDownMenuModelWithMenuItemTitle:@"Facebook" menuItemIconName:@"menu5" menuBlock:^{
MenuViewController *vc = [MenuViewController new];
vc.navigationItem.title = @"Facebook";
[weakSelf.navigationController pushViewController:vc animated:YES];
}];
NSArray *menuModelArr = @[menuModel0, menuModel1, menuModel2, menuModel3, menuModel4, menuModel5];
return menuModelArr;
}
/** 显示下拉菜单 */
- (void)showDropDownMenu {
[self.dropdownMenu showMenu];
}
//=================================================================
// FFDropDownMenuViewDelegate
//=================================================================
#pragma mark - FFDropDownMenuViewDelegate
/** 可以在这个代理方法中稍微小修改cell的样式,比如是否需要下划线之类的 */
/** you can modify menu cell style, Such as if should show underline */
- (void)ffDropDownMenuView:(FFDropDownMenuView *)menuView WillAppearMenuCell:(FFDropDownMenuBasedCell *)menuCell index:(NSInteger)index {
//若果自定义cell的样式,则在这里将 menuCell 转换成你自定义的cell
FFDropDownMenuCell *cell = (FFDropDownMenuCell *)menuCell;
//如果自定义cell,你可以在这里进行一些小修改,比如是否需要下划线之类的
//最后一个菜单选项去掉下划线(FFDropDownMenuCell 内部已经做好处理,最后一个是没有下划线的,以下代码只是举个例子)
if (menuView.menuModelsArray.count - 1 == index) {
cell.separaterView.hidden = YES;
}
else {
cell.separaterView.hidden = NO;
}
}
@end
网友评论