2017-03-16 62 views
1

我使用的UITabBarController 5的ViewController各自的ViewController具有自己的UINavigationController如下:顯示所選UITabBarItem(故事板)原始圖像iOS10

enter image description here

我已經加入塔巴爾圖像等

enter image description here

從上圖可以看出,當Tab BarItem被選中爲藍色圖像,我可以看到...我想顯示選定tabaritem的原始圖像。

我曾經看過設置屬性UIImageRenderingModeAlwaysOriginal的例子。但我在故事板上看不到任何東西。

下面是我推TabBarController方式:

HomeViewController *vcHome = (HomeViewController*)[[UIStoryboard storyboardWithName:@"NexTabBar" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"ID_HOME_VC"]; 
vcHome.delegate = self; 
[self.navigationController pushViewController:vcHome animated:YES]; 

我如何使用屬性UIImageRenderingModeAlwaysOriginal這裏來,選擇時特別TabBarItem是我可以看到原始圖像?

或者如果有任何其他方式與ios10。

+0

你的第一個圖像太模糊,你能提供一個高分辨率的圖像嗎? – aircraft

+0

它只是在StoryBoard中的UITabBarController ....有五個TabBarItem ....基本的控制器我只能拿出屏幕短褲.... – user2813740

+0

有屬性UIImageRenderingModeAlwaysOriginal但我不知道如何在我的情況下使用..當我們從故事板加載UITabBarController並且不是編程式的時... – user2813740

回答

1

這是我如何創建tabBarItem爲myTabBar

let storyboard = UIStoryboard(name: storyboardIdentifier, bundle: nil) 
    let vc:UIViewController? = storyboard.instantiateInitialViewController(); 
    let selectedImage = UIImage(named: imageName) 
    let notSelectedImage = UIImage(named:selectedImageName)?.withRenderingMode(.alwaysOriginal) 
    let item = UITabBarItem(title: title, image: notSelectedImage, selectedImage: selectedImage) 
    vc!.tabBarItem = item 

目標C版本:

UIStoryboard *sb = [UIStoryboard storyboardWithName:storyboardIdentifier bundle:nil]; 
UIViewController* vc = sb.instantiateInitialViewController; 
UIImage* selectedImage = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 
UIImage* notSelectedimage = [[UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 
UITabBarItem* item = [[UITabBarItem alloc]initWithTitle:title image:notSelectedimage selectedImage:selectedImage]; 
[[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]]; 
vc.tabBarItem = item; 
return vc; 

如果這沒有幫助嘗試改變還的TabBar色調的顏色

self.tabBar.barTintColor = .orange 

    // set color of selected icons and text to white 
    self.tabBar.tintColor = .white 
    UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.white], for: .selected) 


    // set color of unselected text to gray 
    UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.gray], for: .normal) 
+0

如果可能的話,請給我目標C,我有五個UITabBarItem ... – user2813740

+0

所以我需要添加5個UITabBarItem *項正確嗎? – user2813740

+0

我試過了,但它只是將未選中的顏色更改爲白色,因爲setSelectedImageTintColor不可用,所以我添加了setUnSelectedItemTintColor。當圖像被選中時,它仍然顯示藍色的默認圖像...... :( – user2813740