如何在obcjective -c中更改编辑和完成按钮的文本?

时间:2015-06-01 07:27:57

标签: ios button text edit title

我想更改导航栏上的“编辑”和“完成”按钮的文本,在我用Objective-c编写的iOS应用中,我该怎么做?

2 个答案:

答案 0 :(得分:0)

这是你想要的。

    UIButton *btncustome = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 60, 30)];
    [btncustome setTitle:@"Edit" forState:UIControlStateNormal];
    [btncustome setTitle:@"Done" forState:UIControlStateSelected];

    UIBarButtonItem *rightbtn = [[UIBarButtonItem alloc]initWithCustomView:btncustome] ;
    self.navigationController.navigationItem.rightBarButtonItem = rightbtn;

答案 1 :(得分:-1)

UINavigationController获取UIBarButton并使用setTitle方法更改文字。

UINavigationItem *items = [[[[self navigationController] navigationBar] items] lastObject];

    UIBarButtonItem *cancelButton = [item leftBarButtonItem];
    UIBarButtonItem *editButton = [item rightBarButtonItem];

    [cancelButton setTitle:@"New Title"];
    [editButton setTitle:@"New Title"];