2013-06-20 50 views
0

我試圖自定義一個tabbar,我使用下面的代碼來改變背景。UITabBar setBackgroundImage not working

UIImage *TabBarControllerBackground = [UIImage imageNamed:@"ios7TabBarBackground"]; 
[[UITabBar appearance] setBackgroundImage:TabBarControllerBackground forBarMetrics:UIBarMetricsDefault]; 

我得到以下錯誤:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_UIAppearance setBackgroundImage:forBarMetrics:]: unrecognized selector sent to instance 0x1e868a80'

這是爲什麼?它很適合改變我的導航欄。

+0

你想改變tabbar tint color嗎? – Purva

回答

1

讓我們來看看這個錯誤接近:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_UIAppearance setBackgroundImage:forBarMetrics:]: unrecognized selector sent to instance 0x1e868a80' 

什麼它告訴你的是,UIAppearance沒有實現setBackgroundImage:forBarMetrics:選擇。

你需要放棄最後一個參數 - 顯然UIAppearance不喜歡它。把它變成這樣:

[[UITabBar appearance] setBackgroundImage:TabBarControllerBackground];