2012-07-16 72 views
0

我正在使用iOS 5.1與StoryBoards。我想改變標準頁面捲曲按鈕的色調,但我似乎也不能。爲什麼我無法更改UIBarButtonSystemItemPageCurl項目色調?

該按鈕位於View Controller上,並且是導航控制器的推送視圖控制器。我改變了導航控制器上的色調,推斷出工具欄。工具欄以所需的顏色顯示。

我viewDidLoad方法如下:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // adjust the color of the curl button 
    if (self.curlButton) { 
     NSMutableArray * toolbarItems = [self.toolbarItems mutableCopy]; 
     [toolbarItems removeObject:self.curlButton]; 
     UIColor *barColor = self.navigationController.toolbar.tintColor; 
     UIBarButtonItem *newPageCurl = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPageCurl target:self.curlButton.target action:self.curlButton.action]; 
     newPageCurl.tintColor = barColor; 
     NSLog(@"%@", newPageCurl.tintColor); 
     [toolbarItems addObject:newPageCurl]; 
     self.toolbarItems = toolbarItems; 
    } 
} 

self.curlButton是對於在界面生成器配置的頁面捲曲按鈕的出口。

我已經試過了,只是在self.curlButton中設置了色調,最初爲零,但沒有奏效,該按鈕與藍色相同。

因此,有些答案說你必須以編程方式創建一個新按鈕,這就是我在這裏嘗試的。

我確認了barColor包含正確的顏色。我註釋了removeObject行,並且正確地生成了兩個捲曲按鈕,但都是藍色的。

NSLog驗證newPageCurl按鈕是否具有正確的色調集。

我試着在viewDidAppear中做所有這些工作,以防工具欄需要先顯示,但按鈕仍然是藍色的,並且沒有使用新的色調。

回答

0

從iOS 5開始,您應該可以使用外觀選擇器來執行此操作。

(編輯抱歉帶壞WRT捲曲按鈕的外觀或appearanceWhenContainedIn:。似乎一切工作,除了捲曲按鈕...甚至其他系統欄按鈕項捲曲,一個用戶說,UIBarButtonSystemItem PageCurl does not change color with the toolbar解決方案但是當我測試了它,它並沒有爲我工作。)

if ([[UIBarButtonItem class] respondsToSelector:@selector(appearanceWhenContainedIn:)]) 
    { 
     id barButtonAppearance 
      = [UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]; 
     [barButtonAppearance setTintColor:self.navigationController.toolbar.tintColor]; 
     barButtonAppearance 
      = [UIBarButtonItem appearanceWhenContainedIn:[UIToolBar class], nil]; 
     // you'll have to have toolbar already, or pick something like [UIColor chartreuseColor] or whatever 
     [barButtonAppearance setTintColor:toolbar.tintColor]; 
    } 
+0

不幸的是,不會改變頁面捲曲按鈕的顏色。它還具有將標準按鈕圖標從工具欄的白色更改爲淺色的不良副作用。 – Peter 2012-07-17 18:49:58

+0

已更新,並提供鏈接以提供真正的解決方案,並提供更好的解決方案w.r.t.確保按鈕只在適當的欄中更改。 – 2012-07-17 19:25:01

+0

嗯......也許我應該放棄這個問題。我只是在自己的鏈接答案中嘗試了這個建議,而鏈接答案的用戶表示它對他有用,但它對我並不起作用。 – 2012-07-17 19:38:46

相關問題