实现简单地小菜单效果

这里写图片描述

@interface ViewController ()
@property(nonatomic,retain)UIImageView *myImageView;
//BOOL属性进行状态判断
@property(nonatomic,assign)BOOL isDid;
@end
self.view.backgroundColor = [UIColor whiteColor];
//设置navigationItem按钮
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"点击" style:UIBarButtonItemStylePlain target:self action:@selector(Action)];
//添加imageView在view上
self.myImageView = [[UIImageView alloc]initWithFrame:CGRectMake(250, 0, 120, 125)];
self.myImageView.backgroundColor = [UIColor grayColor];
    [self.view addSubview:self.myImageView];
    //将想要添加的按钮添加在imageView上
    MenuButton *firstButton = [[MenuButton alloc]initWithFrame:CGRectMake(0, 0, 120, 40)];
    firstButton.backgroundColor = [UIColor blackColor];
    [firstButton addTarget:self action:@selector(firstAction) forControlEvents:UIControlEventTouchUpInside];
    [self.myImageView addSubview:firstButton];

    MenuButton *secondButton = [[MenuButton alloc]initWithFrame:CGRectMake(0, 40, 120, 40)];
    secondButton.backgroundColor = [UIColor redColor];
    [secondButton addTarget:self action:@selector(secondAction) forControlEvents:UIControlEventTouchUpInside];
    [self.myImageView addSubview:secondButton];

    MenuButton *thirdButton = [[MenuButton alloc]initWithFrame:CGRectMake(0, 80, 120, 40)];
    thirdButton.backgroundColor = [UIColor yellowColor];
    [thirdButton addTarget:self action:@selector(thirdAction) forControlEvents:UIControlEventTouchUpInside];
    [self.myImageView addSubview:thirdButton];

    //打开imageView的用户交互
    self.myImageView.userInteractionEnabled = YES;
    //初始隐藏imageView
    self.myImageView.hidden = YES;
    //状态为yes
    self.isDid = YES;

}
//点击按钮
- (void)Action{
    if (self.isDid == NO) {
        self.myImageView.hidden = YES;
    }else{
        self.myImageView.hidden = NO;
    }
    //取反操作
    self.isDid = !self.isDid;

}
//打印事件
- (void)firstAction{
    NSLog(@"1");
}
- (void)secondAction{
    NSLog(@"2");
}
- (void)thirdAction{
    NSLog(@"3");
}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值