首页 技术 正文
技术 2022年11月20日
0 收藏 804 点赞 5,136 浏览 5400 个字

Demo地址:
https://github.com/chenfanfang/CollectionsOfExample
FFDropDownMenu框架地址:
https://github.com/chenfanfang/FFDropDownMenu

老样子,先附上两张效果图

iOS 下拉菜单 FFDropDownMenu自定义下拉菜单样式实战-b

customMenuStyle.gif

iOS 下拉菜单 FFDropDownMenu自定义下拉菜单样式实战-b

customMenuStyle.png


  • 首先自定义一个继承于FFDropDownMenuBasedModel的菜单模型
    .h文件

#import <FFDropDownMenuBasedModel.h>
@interface FFDropDownCustomMenuStyle1Model : FFDropDownMenuBasedModel
/** 主标题的背景颜色 */
@property (nonatomic, strong) UIColor *mainTitleBgColor;
/** 主标题 */
@property (nonatomic, copy) NSString *mainTitle;
/** 副标题 */
@property (nonatomic, copy) NSString *subTitle;
//菜单模型创建的属性用于自定义菜单cell,所以需要什么属性,自己定义@end

.m文件

#import "FFDropDownCustomMenuStyle1Model.h"
@implementation FFDropDownCustomMenuStyle1Model
@end

  • 其次自定义一个继承于FFDropDownMenuBasedCell的cell

FFDropDownCustomMenuStyle1Cell.h

#import <FFDropDownMenuView.h>
/**  
*  自定义菜单效果1 菜单 cell  
*/
@interface FFDropDownCustomMenuStyle1Cell : FFDropDownMenuBasedCell
@end

FFDropDownCustomMenuStyle1Cell.m

#import "FFDropDownCustomMenuStyle1Cell.h"
//model
#import "FFDropDownCustomMenuStyle1Model.h"
@interface FFDropDownCustomMenuStyle1Cell ()
@property (weak, nonatomic) IBOutlet UILabel *mainTitle_Label;
@property (weak, nonatomic) IBOutlet UILabel *subTitle_Label;
@end@implementation FFDropDownCustomMenuStyle1Cell
- (void)setMenuModel:(id)menuModel {      
   _menuModel = menuModel;    
   //在这里将模型转成自定义的模型    
   FFDropDownCustomMenuStyle1Model *realModel = (FFDropDownCustomMenuStyle1Model *)menuModel;    
   self.mainTitle_Label.backgroundColor = realModel.mainTitleBgColor;    
   self.mainTitle_Label.text = realModel.mainTitle;    
   self.subTitle_Label.text = realModel.subTitle;
}
@end

cell的xib布局图如下

iOS 下拉菜单 FFDropDownMenu自定义下拉菜单样式实战-b

Snip20160915_1.png


  • 最后就可以创建下拉菜单了

#import "FFDropDownCustomMenuStyle1VC.h"
//controller
#import "FFDropDownMenuNextPageVC.h"
//view
#import <FFDropDownMenuView.h>
//model
#import "FFDropDownCustomMenuStyle1Model.h"
@interface FFDropDownCustomMenuStyle1VC ()
/** 下拉菜单 */
@property (nonatomic, strong) FFDropDownMenuView *dropDownMenu;
@end@implementation FFDropDownCustomMenuStyle1VC
- (void)viewDidLoad {    
   [super viewDidLoad];      
   [self createDropdownMenu];      
   [self setupNav];
}
- (void)createDropdownMenu {    
   NSArray *menuModelsArr = [self getDropDownMenuModelsArray];    
   self.dropDownMenu = [FFDropDownMenuView new];    
   //设置动画效果,可以根据项目需求设置自己所需要的动画效果
   self.dropDownMenu.menuAnimateType = FFDropDownMenuViewAnimateType_FallFromTop;    
   //若不需要灰色透明蒙板,下面的两个透明度可以设置为0     self.dropDownMenu.bgColorbeginAlpha = 0;    
   self.dropDownMenu.bgColorEndAlpha = 0;    
   //设置下拉菜单的宽度为整个屏幕的宽度     self.dropDownMenu.menuWidth = [UIScreen mainScreen].bounds.size.width;    
   //设置菜单距离屏幕右边的边距为0     self.dropDownMenu.menuRightMargin = 0;    
   //取消菜单圆角效果     self.dropDownMenu.menuCornerRadius = 0;    
   //隐藏三角形     self.dropDownMenu.triangleSize = CGSizeZero;    
   self.dropDownMenu.eachMenuItemHeight = 70;    
   self.dropDownMenu.menuModelsArray = menuModelsArr;    
   self.dropDownMenu.cellClassName = @"FFDropDownCustomMenuStyle1Cell.xib";    
   self.dropDownMenu.menuItemBackgroundColor = FFColor(255, 255, 255, 0.7);    
   [self.dropDownMenu setup]; }
/** 获取下拉菜单模型数组 */
- (NSArray *)getDropDownMenuModelsArray {    
   __weak typeof(self)weakSelf = self;      
   FFDropDownCustomMenuStyle1Model *menuModel1 = [FFDropDownCustomMenuStyle1Model new];    
   menuModel1.mainTitleBgColor = FFColor(54, 188, 37, 1);    
   menuModel1.mainTitle = @"1";    
   menuModel1.subTitle = @"First Menu Item";    
   menuModel1.menuBlock = ^ {        
       FFDropDownMenuNextPageVC *vc = [FFDropDownMenuNextPageVC new];        
       vc.navigationItem.title = @"First Menu Item";        
       [weakSelf.navigationController pushViewController:vc animated:YES];    
   };      
   FFDropDownCustomMenuStyle1Model *menuModel2 = [FFDropDownCustomMenuStyle1Model new];    
   menuModel2.mainTitleBgColor = FFColor(255, 199, 40, 1);    
   menuModel2.mainTitle = @"2";    
   menuModel2.subTitle = @"Second Menu Item";    
   menuModel2.menuBlock = ^ {        
       FFDropDownMenuNextPageVC *vc = [FFDropDownMenuNextPageVC new];        
       vc.navigationItem.title = @"Second Menu Item";        
       [weakSelf.navigationController pushViewController:vc animated:YES];    
   };      
   FFDropDownCustomMenuStyle1Model *menuModel3 = [FFDropDownCustomMenuStyle1Model new];    
   menuModel3.mainTitleBgColor = FFColor(255, 81, 31, 1);    
   menuModel3.mainTitle = @"3";    
   menuModel3.subTitle = @"Third Menu Item";    
   menuModel3.menuBlock = ^ {    
       FFDropDownMenuNextPageVC *vc = [FFDropDownMenuNextPageVC new];        
       vc.navigationItem.title = @"Facebook";        
       [weakSelf.navigationController pushViewController:vc animated:YES];    
   };      
   FFDropDownCustomMenuStyle1Model *menuModel4 = [FFDropDownCustomMenuStyle1Model new];    
   menuModel4.mainTitleBgColor = FFColor(18, 170, 158, 1);    
   menuModel4.mainTitle = @"4";    
   menuModel4.subTitle = @"Fourth Menu Item";    
   menuModel4.menuBlock = ^ {    
       FFDropDownMenuNextPageVC *vc = [FFDropDownMenuNextPageVC new];        
       vc.navigationItem.title = @"Facebook";        
       [weakSelf.navigationController pushViewController:vc animated:YES];    
   };      
   FFDropDownCustomMenuStyle1Model *menuModel5 = [FFDropDownCustomMenuStyle1Model new];    
   menuModel5.mainTitleBgColor = FFColor(0, 119, 195, 1);    
   menuModel5.mainTitle = @"5";    
   menuModel5.subTitle = @"Fifth Menu Item";    
   menuModel5.menuBlock = ^ {        
       FFDropDownMenuNextPageVC *vc = [FFDropDownMenuNextPageVC new];        
       vc.navigationItem.title = @"Facebook";        
       [weakSelf.navigationController pushViewController:vc animated:YES];    
   };    
   NSArray *menuModelArr = @[menuModel1,menuModel2,menuModel3,menuModel4,menuModel5];    
   return menuModelArr;
}
/** 初始化导航栏 */
- (void)setupNav {    
   self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self.dropDownMenu action:@selector(showMenu)];    
   self.navigationItem.title = @"实战:自定义菜单效果1";
}
@end
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,104
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,580
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,428
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,200
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,835
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,918