- An easy,friendly and customizable way to make a popover menu.
Installation
Cocoapods
pod "FCPopMenu", "~>1.0"
Use pod repo update
if not exist.
Manual
Download FCPopMenu
,drag folder "FCPopMenu" into your project, make sure to ues "create group if need".
Useage
How to create FCPopMenuItems
NSArray *names=@[@"新建剧情",@"发布招募",@"搜一搜"];
NSArray *imgs=@[@"sence_new",@"recruit_new",@"sence_search"];
NSMutableArray *items=[NSMutableArray array];
__weak typeof(self) wkself=self;
for(int i=0;i<names.count;i++){
FCPopMenuItem *item=[FCPopMenuItem itemWithImage:[UIImage imageNamed:imgs[i]]
title:names[i]
titleColor:[UIColor whiteColor]
handler:^(FCPopMenuItem *sender) {
[wkself listClickAction:sender];
}];
[items addObject:item];
}
FCPopMenu
Create a popover menu like this
_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);
You may need a overlay view
-(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;
}
Troggle show/close menu
-(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;
}
Monitor click action
-(void)listClickAction:(FCPopMenuItem *)sender{
[self hideList:self.back];
NSString *title=[sender.title copy];
if([title isEqualToString:@"新建剧情"]){
}else if([title isEqualToString:@"发布招募"]){
}else{
}
NSLog(@"%@",sender.title);
}
Hide
-(void)hideList:(UIControl *)sender{
[sender removeFromSuperview];
[self.list removeFromSuperview];
}
Source code on github click-> here
About Me
- Blog: CGPointZeero
- GitHub: Insfgg99x
- Mooc: CGPointZero
- Jianshu: CGPointZero
- Email: newbox0512@yahoo.com
@CGPoitZero
网友评论