2012-11-28 88 views
1

我的導航欄上有一個簡單的編輯按鈕,一旦點擊就轉到完成,我試圖將「編輯」和「完成」上的文本更改爲大寫文本,這可能嗎?有人知道我可以查看一個教程嗎?RightBarButtonItem大寫字母文本?

self.navigationItem.rightBarButtonItem = self.editButtonItem; 

謝謝。

+1

您應該注意,編輯a完成按鈕會自動本地化爲用戶選擇的語言,並且替換它們將刪除此功能。加上大寫的文本看起來很簡單....你是否喜歡它,當人們關注所有的時間? – ikuramedia

回答

1

在h文件創建的UIBarButtonItem btnEdit對象像波紋管:

UIBarButtonItem *btnEdit; 

,然後在.m文件寫這樣的代碼:

- (void)viewWillAppear:(BOOL)animated{ 
    btnEdit = [[UIBarButtonItem alloc]init]; 
    btnEdit.target = self; 
    btnEdit.action = @selector(btnEdit_Click:); 
    btnEdit.title = @"EDIT"; 
    self.navigationController.topViewController.navigationItem.rightBarButtonItem = btnEdit; 
    btnEdit.enabled=TRUE; 
} 

- (IBAction)btnEdit_Click:(id)sender 
{ 
    if ([btnEdit.title isEqualToString:@"EDIT"]) 
    { 
     [btnEdit setTitle:@"DONE"]; 
    } 
    else 
    { 
     [btnEdit setTitle:@"EDIT"]; 
    } 
} 
0
UIBarButtonItem *newButton = [[UIBarButtonItem alloc] initWithTitle: @"EDIT" style: UIBarButtonItemStyleBordered target: nil action: @selector(editPressed:self)]; 

[[self navigationItem] setRightBarButtonItem: newButton animated:NO]; 

newBackButton = nil; 

然後:

- (void)editPressed:(id)sender 
{ 
    // Your code 
}