美文网首页
iOS navigationBar 添加UIBarButtonI

iOS navigationBar 添加UIBarButtonI

作者: 浪高达 | 来源:发表于2017-02-28 12:08 被阅读356次

方式一:

1.设置按钮
    // 设置左边按钮
    UIBarButtonItem *leftBtnItem = [[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStyleDone target:self action:@selector(rightBarBtnAction:)];
    self.navigationItem.rightBarButtonItem = leftBtnItem;
2.设置跳转到的页面
-(void)rightBarBtnAction:(UIBarButtonItem*)sender{
    // push到下个界面
    CSCanteenListTabVController *secondVC = [[CSCanteenListTabVController alloc]init];
    [self.navigationController pushViewController:secondVC animated:YES];
}

方式二:

1.设置按钮
UIButton *cancleButton = [UIButton buttonWithType:UIButtonTypeSystem];
    cancleButton.frame = CGRectMake(0, 0, 80, 40);
    [cancleButton setTitle:@"撤销" forState:UIControlStateNormal];
    [cancleButton setTitleColor:[UIColor nzq_colorWithHex:0x111111] forState:UIControlStateNormal];
    [cancleButton addTarget:self action:@selector(rightBarBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:cancleButton];
    self.navigationItem.rightBarButtonItem = rightItem;
2.设置跳转到的页面
-(void)rightBarBtnAction:(UIBarButtonItem*)sender{
    // push到下个界面
    CSCanteenListTabVController *secondVC = [[CSCanteenListTabVController alloc]init];
    [self.navigationController pushViewController:secondVC animated:YES];
}

相关文章

网友评论

      本文标题:iOS navigationBar 添加UIBarButtonI

      本文链接:https://www.haomeiwen.com/subject/njdxgttx.html