ios--右侧视图DropDownMenuView

ios--右侧视图DropDownMenuView_第1张图片

导入第三方FFDropDownMenu

#import "AppDelegate.h"

//controller

#import "FFHomeViewController.h"

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[FFHomeViewController new]];

[nav.navigationBar setTitleTextAttributes:@{

NSFontAttributeName : [UIFont boldSystemFontOfSize:18],

NSForegroundColorAttributeName : [UIColor whiteColor]

}];

self.window.rootViewController = nav;

self.window.backgroundColor = [UIColor whiteColor];

[self.window makeKeyAndVisible];

[application setStatusBarStyle:UIStatusBarStyleLightContent];



//FFHomeViewController.m

//controller

#import "FFMenuViewController.h"

//view

#import "FFDropDownMenuView.h"


/** 下拉菜单 */

@property (nonatomic, strong) FFDropDownMenuView *dropdownMenu;


//==============================

/** 初始化下拉菜单 */

[self setupDropDownMenu];

/** 进行基本的设置、读者可忽略setupBasedView 中的代码 */

[self setupBasedView];

//=========================================

/** 初始化下拉菜单 */

- (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:@"TabBar_public_1@2x"  menuBlock:^{

FFMenuViewController *vc = [FFMenuViewController new];

vc.navigationItem.title = @"QQ";

[weakSelf.navigationController pushViewController:vc animated:YES];

}];

//菜单模型1

FFDropDownMenuModel *menuModel1 = [FFDropDownMenuModel ff_DropDownMenuModelWithMenuItemTitle:@"Line" menuItemIconName:@"TabBar_public_1@2x" menuBlock:^{

FFMenuViewController *vc = [FFMenuViewController new];

vc.navigationItem.title = @"Line";

[weakSelf.navigationController pushViewController:vc animated:YES];

}];

//菜单模型2

FFDropDownMenuModel *menuModel2 = [FFDropDownMenuModel ff_DropDownMenuModelWithMenuItemTitle:@"Twitter" menuItemIconName:@"TabBar_public_1@2x" menuBlock:^{

FFMenuViewController *vc = [FFMenuViewController new];

vc.navigationItem.title = @"Twitter";

[weakSelf.navigationController pushViewController:vc animated:YES];

}];

//菜单模型3

FFDropDownMenuModel *menuModel3 = [FFDropDownMenuModel ff_DropDownMenuModelWithMenuItemTitle:@"QZone" menuItemIconName:@"TabBar_public_1@2x"  menuBlock:^{

FFMenuViewController *vc = [FFMenuViewController new];

vc.navigationItem.title = @"QZone";

[weakSelf.navigationController pushViewController:vc animated:YES];

}];

//菜单模型4

FFDropDownMenuModel *menuModel4 = [FFDropDownMenuModel ff_DropDownMenuModelWithMenuItemTitle:@"WeChat" menuItemIconName:@"TabBar_public_1@2x"  menuBlock:^{

FFMenuViewController *vc = [FFMenuViewController new];

vc.navigationItem.title = @"WeChat";

[weakSelf.navigationController pushViewController:vc animated:YES];

}];

//菜单模型5

FFDropDownMenuModel *menuModel5 = [FFDropDownMenuModel ff_DropDownMenuModelWithMenuItemTitle:@"Facebook" menuItemIconName:@"TabBar_public_1@2x"  menuBlock:^{

FFMenuViewController *vc = [FFMenuViewController 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;

}

}

//==================================================================

//  进行基本的设置、搭建出手机QQ首页效果、读者可忽略setupBasedView 中的代码

//  you can ignore below code

//==================================================================

- (void)setupBasedView {

//右侧的菜单按钮

UIButton *menuBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];

[menuBtn addTarget:self action:@selector(showDropDownMenu) forControlEvents:UIControlEventTouchUpInside];

[menuBtn setImage:[UIImage imageNamed:@"nemuItem"] forState:UIControlStateNormal];

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:menuBtn];

}

//FFMenuViewController.m 什么都没有

你可能感兴趣的:(ios--右侧视图DropDownMenuView)