按钮弹窗

代码

#import "VideoViewController.h"

@interface VideoViewController ()
{
    UIBarButtonItem *rightBtn ;
    UIButton *btn;
    UIView *BtnView ;
}
@end

@implementation VideoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self nav];
    
}
-(void)nav{
    self.title = @"视频";
    [self.navigationController.navigationBar setTitleTextAttributes:
     
  @{NSFontAttributeName:[UIFont systemFontOfSize:23],
    
    NSForegroundColorAttributeName:[UIColor whiteColor]}];
    

    self.navigationController.navigationBar.barTintColor = [UIColor blackColor];
    
    btn = [[UIButton alloc] init];
    btn.frame = CGRectMake(0, 0  , 40, 40);
   // btn.backgroundColor = [UIColor redColor];
  BtnView = [[UIView alloc] initWithFrame:CGRectMake(300, 65, 100, 120)];
    [btn addTarget:self action:@selector(abc) forControlEvents:UIControlEventTouchUpInside];
  [ btn setTitle:@"+" forState:UIControlStateNormal];
    btn.font = [UIFont systemFontOfSize:23];
    BtnView.backgroundColor = [UIColor redColor];
    
    UIButton *bt1 = [[UIButton alloc]initWithFrame:CGRectMake(20, 10, 30, 20)];
    bt1.backgroundColor = [UIColor whiteColor];
    [BtnView addSubview:bt1];
    
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
     self.navigationItem.rightBarButtonItem = rightItem;
    [self.view addSubview:BtnView];
    //[self.view addSubview:btn];
    BtnView.hidden = YES;
    btn.selected = YES;

}




-(void)abc{
    
    if (btn.selected ==  YES) {
        BtnView.hidden = NO;
        btn.selected = NO;
    }else if(btn.selected == NO)
    {
        BtnView.hidden = YES;
        btn.selected = YES;
        
    }
//        UIView *BtnView = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 100, 100)];
//        BtnView.backgroundColor = [UIColor redColor];
//        [self.view addSubview:BtnView];
//    }
   
}

运行效果图:
按钮弹窗_第1张图片

你可能感兴趣的:(按钮弹窗)