2012-07-08 47 views
0

我在xcode 4.2中創建了新的標籤欄項目,並且沒有應用程序委託xib文件。項目有兩個導航控制器。我可以設置標籤欄的名稱,但無法設置圖像。我完全厭倦了很多嘗試。 FirstViewController *firstView = [[FirstViewController alloc] initWithNibName:@"FirstViewController_iPhone" bundle:nil] 無法在Xcode 4.2中設置標籤欄圖像編程

[email protected]"Birthdays"; 
firstView.tabBarItem.image=[UIImage imageNamed:@"bottomleft.png"]; 
SecondViewController *secondView = [[SecondViewController alloc] initWithNibName:@"SecondViewController_iPhone" bundle:nil]; 
[email protected]"Settings"; 
secondView.tabBarItem.image=[UIImage imageNamed:@"bottomright.png"]; 
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:secondView]; 
    navController2.navigationBarHidden=YES; 
    [viewControllers addObject:navController2]; 

enter image description here

在這裏你可以看到我得到什麼樣的輸出。

回答

1

很難從您發佈的代碼中分辨出來,但您可能想要等上UINavigationControllernavController2)的tabBarItem的圖像,因爲它看起來像這就是你直接添加到您UITabBarController

navController2.tabBarItem.image = [UIImage imageNamed:@"bottomright.png"]; 

您可以設置標題的原因是默認的導航控制器會自動有他們當前的子視圖控制器的標題。

0

你永遠需要做到這一點:

[UIImage imageNamed:@"bottomleft2x.png"]; 

UIImage會自動判斷@2x是否需要或不基於屏幕比例,所以要簡單說:

[UIImage imageNamed:@"bottomleft.png"]; 

除非,當然,您的資源名稱實際上是[email protected]

+0

Coneybeare,我也做了同樣的事情,但仍然得到相同的結果。你可以在我的答案中看到圖像。 – josh 2012-07-08 17:56:38

+0

有時xcode無法將文件添加到項目中,可能需要手動刪除並再次添加到xcode – 2012-07-09 06:50:02

1

看起來您已成功替換左側圖像,但它沒有透明區域。您是否遵循了設計選項卡圖標的指導原則?

http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/mobilehig/IconsImages/IconsImages.html

您需要在透明背景上使用白色圖像。如果您的背景不透明,則整個圖像將只是一個藍色框,就像您左側標籤上的那個。

示例:要製作帶有星形的選項卡,請在透明背景上繪製完全白色的星形。不要使用除完全白色和透明黑色之外的其他顏色。

+0

這是您的問題。我在這裏找到了一個非常直接的教程:http://greenerpastures.dk/blog/iphone-udvikling/how-to-make-tab-bar-icons – ravron 2012-07-12 03:06:13

0

哥們標籤欄只允許白色和透明背景,所以如果你想讓圖片像生日蛋糕,然後在透明的背景上畫一個白色的生日蛋糕,然後在蛋糕上添加一些透明像素來創建外觀一個蛋糕,而不是隻是蛋糕的輪廓,然後你可以設置年圖像標籤欄