最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
iOS创建简单的菜单的例子
时间:2016-04-17 编辑:简简单单 来源:一聚教程网
-(void)createMeunView
{
UIButton *showMeunViewButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 100, 40)];
showMeunViewButton.center = self.view.center;
[showMeunViewButton setTitle:@"显示菜单" forState:UIControlStateNormal];
[showMeunViewButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[showMeunViewButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateSelected];
[showMeunViewButton addTarget:self action:@selector(showMeunViewButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:showMeunViewButton];
showMeunView = [self createMeunView:showMeunViewButton buttonTitles:@[@"1",@"2",@"3",@"4",@"5"] menuButtonTagStart:300];
[self.view addSubview:showMeunView];
}
-(void)showMeunViewButtonAction:(UIButton *)button
{
button.selected = !button.selected;
if (button.selected) {
showMeunView.hidden = NO;
}else
{
showMeunView.hidden = YES;
}
}
#pragma mark -- 封装创建菜单的方法
-(UIView *)createMeunView:(UIButton *)button buttonTitles:(NSArray *)buttonTitles menuButtonTagStart:(NSInteger)tagStart
{
//button菜单显示在这个参数下面,buttonTitles菜单按钮的标题数组,tagStart菜单按钮tag起始值用于区别点击了哪个按钮
UIView *menuView = [[UIView alloc]initWithFrame:CGRectMake(button.minX, button.maxY, button.width, 41 * buttonTitles.count)];
menuView.hidden = YES;
menuView.backgroundColor = [UIColor blackColor];
for (int i = 0; i < buttonTitles.count; i++)
{
UIButton *menuButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 41 * i, menuView.width, 40)];
menuButton.backgroundColor = [UIColor brownColor];
[menuButton setTitle:buttonTitles[i] forState:UIControlStateNormal];
menuButton.titleLabel.font = FONT(14);
[menuButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[menuButton addTarget:self action:@selector(menuButtonAction:) forControlEvents:UIControlEventTouchUpInside];
menuButton.tag = tagStart + i;
[menuView addSubview:menuButton];
}
return menuView;
}
-(void)menuButtonAction:(UIButton *)button
{
NSLog(@"%lu",button.tag);
}
相关文章
- 简单滑动菜单代码 07-11
- 树状菜单的简单实现 03-06
- sora软件价格介绍 02-22
- sora官网入口地址一览 02-22
- Sora生成的视频使用教程 02-22
- 《梦幻西游》元宵灯谜线索答案大全2024 02-22