IOS 判断导航栏navigationItem的按钮的箭头的点击事件

- (void)viewDidLoad

{

//下拉按钮

    UIButton *xialaButton = [UIButtonbuttonWithType:UIButtonTypeCustom];

    xialaButton.frame =CGRectMake(0,0, 50, 30);

    isOpened =NO;

    [xialaButton setTitle:@"你好"forState:UIControlStateNormal];

    [xialaButton setImage:[UIImageimageNamed:@"arrow_down"]forState:UIControlStateNormal];

    [xialaButton addTarget:selfaction:@selector(xialaAction)forControlEvents:UIControlEventTouchUpInside];

    self.navigationItem.titleView = xialaButton;

}

- (void)xialaAction{

   //按钮的上下箭头选项

    UIButton *button = (UIButton *)self.navigationItem.titleView;

   if (isOpened) {

        [button setImage:[UIImageimageNamed:@"arrow_down"]forState:UIControlStateNormal];

       isOpened = NO;

    }

   else{

        [button setImage:[UIImageimageNamed:@"arrow_up"]forState:UIControlStateNormal];

       isOpened = YES;

    }

}

  


你可能感兴趣的:(navigationItem,iOS,navigationItem,UIButton)