2011-03-08 90 views
6

我想在我的導航欄,這是目前定義爲rightBarButtonItem居中一個按鈕一個按鈕:中心的的導航欄

UIBarButtonItem *audioBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:@selector(toggleAudioPlayback:)]; 
self.navigationItem.rightBarButtonItem = audioBtn; 
[audioBtn release]; 

回答

10

您可以使用您的導航項目的.titleView財產 - 但你會需要爲此創建自己的資產(您將無法使用UIBarButtonItem)。從Apple的文檔:

...(titleViews)可以包含按鈕。在UIButton 類中使用 buttonWithType:方法將按鈕添加到導航 欄的樣式的自定義 視圖中。自定義標題視圖在導航欄上居中 ,並可能將 調整爲適合。