一个简单、友好且可定制的弹出菜单制作方法。
一个简单、友好且可定制的下拉菜单
Cocoapods
pod "FCPopMenu", "~>2.0"
如果不存在,请使用 pod repo update
。
如果 pod 找不到 FCPopMenu,使用 pod update
更新 repos
手动 手动
下载 FCPopMenu
,将 "FCPopMenu" 文件夹拖至您的项目中,确保勾选 "create group if need"。
下载 FCPopMenu,并将 "FCPopMenu" 引用到项目中,确保勾选 "create group if need"。
FCPopMenuItem
[FCPopMenuItem itemWithImage:[UIImage imageNamed:@"sence_new"]
title:@"新建剧情"
titleColor:[UIColor whiteColor]
target:self
action:@selector(listClickAction:)];
或者这样
[FCPopMenuItem itemWithImage:[UIImage imageNamed:imgs[i]]
title:names[i]
titleColor:[UIColor whiteColor]
handler:^(FCPopMenuItem *sender) {
[wkself listClickAction:sender];
}];
FCPopMenu
像这样创建一个下拉菜单
_list=[FCPopMenu menuWithFrame:CGRectMake(kFCPopMenuWidth-143, 64, 138, 140) trangleHeight:10 tranglePosition:CGPointMake(112, 0) items:items];
_list.mainColor=[UIColor colorWithRed:73/255.f green:73/255.f blue:73/255.f alpha:1.f];
_list.rowHeight=43.5;
_list.sperateColor=[UIColor colorWithRed:217/255.f green:217/255.f blue:217/255.f alpha:1.f];
_list.seperateInsets=UIEdgeInsetsMake(0, 14, 0, 14);
你可能需要一个覆盖视图,在下拉菜单下方
-(UIControl *)back{
if(!_back){
_back=[[UIControl alloc] initWithFrame:self.view.bounds];
_back.backgroundColor=[UIColor clearColor];
[_back addTarget:self action:@selector(hideList:) forControlEvents:UIControlEventTouchUpInside];
}
return _back;
}
切换显示/隐藏菜单
-(void)addBtnClickAction:(UIBarButtonItem *)sender{
sender.enabled=NO;
if(self.list.superview){
[self hideList:self.back];
sender.enabled=YES;
return;
}
[self.view addSubview:self.back];
[self.view addSubview:self.list];
self.list.alpha=0.0;
__weak typeof(self) wkself=self;
[self.list mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(wkself.view).offset(-5);
make.top.equalTo(wkself.view).offset(64);
make.size.mas_equalTo(CGSizeMake(138, 140));
}];
[UIView animateWithDuration:0.3 animations:^{
wkself.list.alpha=1.0;
}];
sender.enabled=YES;
}
监听点击事件
-(void)listClickAction:(FCPopMenuItem *)sender{
[self hideList:self.back];
NSString *title=[sender.title copy];
if([title isEqualToString:@"新建剧情"]){
}else if([title isEqualToString:@"发布招募"]){
}else{
}
NSLog(@"%@",sender.title);
}
隐藏 隐藏
-(void)hideList:(UIControl *)sender{
[sender removeFromSuperview];
[self.list removeFromSuperview];
}
关于我 关于我
@CGPoitZero