iOS 7.0。
我需要讓你的設計UITabBar。圖片(this link)顯示了它現在的外觀以及外觀。區別在於:
1)某些髒顏色的按鈕上的圖像,應該是白色的
2)所選項目以較暗的背景色突出顯示。現在他根本沒有突出顯示。如何自定義我的UITabBar。漸變背景上的白色圖標
以下是我在應用定義設計AppDelegate.m中:didFinishLaunchingWithOptions
// Background image for TabBar
UIImage *backgroundDownImage = [UIImage imageNamed:@"background_320_49.png"];
// Mode UIImageResizingModeStretch
backgroundDownImage = [backgroundDownImage resizableImageWithCapInsets:UIEdgeInsetsZero resizingMode:UIImageResizingModeStretch];
// Set background image for all UITabBar in application
[[UITabBar appearance] setBackgroundImage:backgroundDownImage];
// White color for TabBar buttons
[[UITabBar appearance] setTintColor:[UIColor whiteColor]];
// Special font for all UITabBarItem
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Xnjslkpqqovrwqxfnmropbgqtzp" size:0], UITextAttributeFont, nil] forState:UIControlStateNormal];
我嘗試了4個變種:
1)在這個方法 - (ID)initWithNibName老代碼setFinishedSelectedImage + withFinishedUnselectedImage
2)在方法 - (id)initWithNibName新代碼setImage + SetSelectedImage
3)在該方法中 - (無效)viewDidLoad中舊代碼
4)在該方法中 - (無效)viewDidLoad中的新代碼
- (void)viewDidLoad
{
[super viewDidLoad];
// Variant 1
[self.tabBarItem setImage:[[UIImage imageNamed:@"Live.png"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal]];
[self.tabBarItem setSelectedImage:[[UIImage imageNamed:@"Live.png"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal]];
// Variant 2
//[self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"Live.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"Live.png"]];
[CommonUse showLiveVideoFromController:self];
}
在所有情況下,圖標將被顯示。方法initWithNibName(選項1和2)顏色圖標上根本沒有任何操作。方法viewDidLoad可以處理新舊代碼 - 但以一種奇怪的方式。當您第一次運行該應用程序時,只有第一個圖標是白色的,而其他所有圖標都是灰色的。如果您點擊任何其他圖標然後回到第一個圖標,該圖標將變成白色(但只有一張圖片!文本仍然是灰色的)。 事實證明,圖標的顏色隻影響方法viewDidLoad,但不完全 - 其他東西丟失。
也許爲Selected和NoSelected繪製兩組圖標。這是在圖標和圖像和文字描述中的圖形。但仍然有兩點:1)當你第一次啓動應用程序時,所有的圖標都是灰色的,只有第一個是白色的。 2)當你改變屏幕的寬度時,如果按鈕不要分散。
比較遺憾的是沒有版本 - iOS7。這是行不通的。 – MinistrBob
它在iOS 7中爲我工作。 – user3663584
它可以工作,但不是我想要的。閱讀我的問題,看看我的照片 - 我想圖標是白色的,不是灰色的。然而,文檔說這些方法在iOS7中已經被描述過了。需要使用[tabBarItem setImage:imageWithRenderingMode:]和[tabBarItem setSelectedImage:imageWithRenderingMode:] – MinistrBob