ios--右侧视图DropDownMenuView

导入第三方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"


<FFDropDownMenuViewDelegate>

/** 下拉菜单 */

@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 什么都没有

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 前言 最近忙完项目比较闲,想写一篇博客来分享一些自学iOS的心得体会,希望对迷茫的你有所帮助。博主非科班出身,一些...
    GitHubPorter阅读 5,319评论 9 5
  • 1.badgeVaule气泡提示 2.git终端命令方法> pwd查看全部 >cd>ls >之后桌面找到文件夹内容...
    i得深刻方得S阅读 10,240评论 1 9
  • 1,Search Bar 怎样去掉背景的颜色(storyboard里只能设置background颜色,可是发现cl...
    以德扶人阅读 7,546评论 2 50
  • *7月8日上午 N:Block :跟一个函数块差不多,会对里面所有的内容的引用计数+1,想要解决就用__block...
    炙冰阅读 7,346评论 1 14
  • 为什么要多读?读书少容易将单一的想法视为绝对的真理。通过主题阅读进行比较,才能进一步确认书的价值。 阅读是为了得到...
    sly61阅读 6,698评论 0 8