我試過setSelectedItem
在viewDidLoad
,也試過selectedIndex
等..無論我在網上找到..但我找不到任何答案。當我啓動應用程序時,每個項目顯示默認狀態下的選項卡欄未處於選定狀態。 我也收到錯誤如何設置默認tabBarItem與色調選擇?
Directly tab bar cannot be modified
我試過setSelectedItem
在viewDidLoad
,也試過selectedIndex
等..無論我在網上找到..但我找不到任何答案。當我啓動應用程序時,每個項目顯示默認狀態下的選項卡欄未處於選定狀態。 我也收到錯誤如何設置默認tabBarItem與色調選擇?
Directly tab bar cannot be modified
你想要做這樣的事情:
UIImage *item2Image = [[UIImage imageNamed:@"simulatorTabBarIconUnselected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *item2ImageSelected = [[UIImage imageNamed:@"simulatorTabBarIconSelected"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UITabBarItem *tabBarItem2 = [[UITabBarItem alloc] initWithTitle:@"Simulator" image:item2Image selectedImage:item2ImageSelected];
設置所選圖像UIImageRenderingModeAlwaysTemplate將着色它作爲您色調的顏色。對於未選擇的圖像,無論如何,蘋果默認爲灰色,所以唯一的解決方法是將其設置爲UIImageRenderingModeAlwaysOriginal,並將圖像資源設置爲您想要的顏色。在我的情況下,我只是做了原始圖像的圖像資產,但阿爾法在50%,所以它看起來淡出,但仍具有相同的色調。
我試過這個 UITabBarItem * tabItem = [[UITabBarItem alloc] initWithTitle:@「Discuss」image:[[UIImage imageNamed:@「u_discuss」] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@「discuss_active」] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]]; 但仍然沒有效果..幫助!! –
將導航控制器tabBarItem屬性設置爲上面的代碼。你的標籤欄應該包含NavigationControllers,其中每個包含視圖控制器 – RDSpinz
我在視圖控制器本身添加了這個。告訴我如何添加這個屬性 –
let accountBoard = UIStoryboard(name: "Account", bundle: nil)
let accountNav = accountBoard.instantiateInitialViewController() as! CommonNavigationController
accountNav.tabBarItem = UITabBarItem(title: "Account", image: UIImage(named: "icon - account")!.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), selectedImage: UIImage(named: "icon - account - white")!.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal))
accountNav.tabBarItem.setTitleTextAttributes([NSFontAttributeName: STYLES.avenirNextDemiBold11!,NSForegroundColorAttributeName: UIColor.whiteColor()], forState: .Normal)
accountNav.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.redColor()], forState:UIControlState.Selected)
您可以編程方式更改未選定項目的顏色屬性。
請粘貼一些示例代碼。 – NRitH
看到這一次可能會幫助你http://stackoverflow.com/questions/22767098/how-to-change-inactive-icon-text-color-on-tab-bar –