我有一個選項卡欄應用程序。並在其中一個標籤欄中有一個導航控制器。 我試圖設置一個圖像的UIButton作爲導航欄的右鍵。UIButton作爲UINavigationbar按鈕
UIButton *refreshButton = [[UIButton alloc] init];
[refreshButton setImage:[UIImage imageNamed:@"refresh_icon.png"] forState:UIControlStateNormal];
[refreshButton addTarget:self action:@selector(refreshSection) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithCustomView:refreshButton];
//[rightButton setImage:[UIImage imageNamed:@"refresh_icon.png"]]; << DOESN'T WORK EITHER
self.navigationItem.rightBarButtonItem = rightButton;
[refreshButton release];
[rightButton release];
但圖像不顯示。我得到一個不可見的按鈕。
編輯: 我希望按鈕風格是純色或背景是透明的,以便只有圖像顯示。因此,我使用的是一個UIbutton,而不是直接使用UIBarButton。
事情是我想要按鈕樣式是平原或背景是透明的。 UIBarButtonItemStyleBordered或其他任何東西把圖像放在一個盒子裏。這就是爲什麼我使用uibutton – Rupert 2010-09-30 08:04:22
你應該在你的問題中提到。正如你指出的那樣,在我展示的導航欄中添加一個按鈕將始終使用邊框顯示它,即使將其設置爲普通樣式也是如此。我認爲它甚至在文檔中提到。 – 2010-09-30 08:07:57
現在它顯示圖像,但點擊它時沒有任何反應。我試過[rightButton setTarget:self]; [rightButton setAction:@selector(refresh :)]; – Rupert 2010-09-30 08:26:58