2011-06-09 30 views

回答

7

這可能使用類似:

[[UIBarButtonItem alloc] initWithImage:@"info.png" style:UIBarButtonItemStyleBordered target:nil action:nil] 

我試着用:

UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:[UIButton buttonWithType:UIButtonTypeInfoLight]]; 
item.style = UIBarButtonItemStyleBordered; 

但它似乎是一個自定義查看接壤的風格沒有得到應用。

18

的圖片按鈕,你已經調用信息button.It是一個系統按鈕,下面

用得到它作爲你的rightBarButtonItem

UIButton* myInfoButton = [UIButton buttonWithType:UIButtonTypeInfoLight]; 
[myInfoButton addTarget:self action:@selector(InfoButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; 
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:myInfoButton]; 

這裏是文檔鏈接UIButtonType

+0

沒錯,但是如果你嘗試這樣做,你會看到你得到的是簡單的樣式,而不是圖像中顯示的邊框樣式。 – 2011-06-09 09:22:51

1

@ Jhaliya的快速複製粘貼答案的Swift版本:

let infoButton = UIButton(type: .InfoLight) 

infoButton.addTarget(self, action: "InfoButtonClicked:", forControlEvents: .TouchUpInside) 

let infoBarButtonItem = UIBarButtonItem(customView: infoButton) 

navigationItem.rightBarButtonItem = infoBarButtonItem