2012-01-03 72 views
6

當我收到將標籤欄的背景圖像更改爲自定義圖像的請求時,我做了一個標籤欄iOS項目。該項目是爲iOS 4.x開發的,因此iOS5的 [tabBar setTabBarBackgroundImage:[UIImage imageNamed:@"custom.jpg"]]不起作用。你能提出一些簡單的解決方案嗎(如果有可能,我不想改變整個項目)?自定義標籤欄背景圖像 - 在iOS 4.x

編輯:代碼 三線僅是可以解決所有:

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"customImage.png"]]; 
[self.tabBarController.tabBar insertSubview:imageView atIndex:0]; 
[imageView release]; 

回答

3

一個可能的解決辦法是把一個UIView與背景圖像完全UITabBar後面。然後將tabbar的不透明度降低到0.5,這樣你就可以看到背景圖像了。

UIView *bckgrndView = [[UIView alloc] initWithFrame:CGRectMake(tabbar.frame.coords.x, tabbar.frame.coords.y, tabbar.frame.size.width, tabbar.frame.size.height)]; 
[bckgrndView setBackgroundImage:[UIImage imageNamed:@"custom.jpg"]]; 
[tabbar.superView insertSubView:bckgrndView belowSubview:tabbar]; 
tabbar.alpha = 0.5; 
[bckgrndView release]; 

對不起,如果我的代碼包含一些錯誤。我試着用心去做這件事......但你會發現漂移。

+0

謝謝你,這是一個有益的想法:) – MMMM 2012-01-03 09:55:50

0

我已經回答了類似問題here。希望它會有所幫助。