UITabBarItem setFinishedSelectedImage: deprecated in iOS7

前端 未结 3 1368
礼貌的吻别
礼貌的吻别 2020-12-14 09:17

setFinishedSelectedImage:withFinishedUnselectedImage: is deprecated in iOS7. Apple recommends to use setters of image and selectedImage

相关标签:
3条回答
  • 2020-12-14 09:33

    The setFinishedSelectedImage is deprecated because Apple wants to direct interfaces toward using the template images and the tintColor you select (or the Blue default.) So, the easy default does the Tab Bar Items that way.

    If you need to still use the Icon image as designed, you create the image with the rendering mode for Always Original. Like:

    [[UIImage imageNamed:@"YourIcon.png"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];
    

    To set the icon you need to get the tabBarItem from the ViewController. What I missed in my app was that each of my tabs had a NavigationController wrapping the top view controller in the tab. Most answers about this subject don't mention getting the navigationContoller and that was key to getting it working in my app.

    So, in my UITableViewContoller subclass I added the following to viewDidLoad.

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
    ...
    
    [self.navigationController.tabBarItem setSelectedImage:[[UIImage imageNamed:@"MySelectedIcon.png"]
     imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal]];
    
    }
    

    The result was the Icon as designed when the tab was selected. If you leave off the imageWithRenderingMode method call, the Icon will be treated as a template colored with the tintColor. Hope this helps.

    0 讨论(0)
  • 2020-12-14 09:39
    class TabBarController: UITabBarController {
    
        override func viewDidLoad() {
            super.viewDidLoad()
    
            self.tabBar.backgroundImage = UIImage()
            self.tabBar.shadowImage = UIImage()
        }
    
    }
    
    0 讨论(0)
  • 2020-12-14 09:55

    If you're are trying to achieve displaying of the actual image at the UITabBar then use the following code.

    [yourTabBarItem setImage:[[UIImage imageNamed:@"more.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    

    and if you want to display image in original condition for the selected then use the following

    [yourTabBarItem setSelectedImage:[[UIImage imageNamed:@"more.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    

    these two are alternative to

    setFinishedSelectedImage:  withFinishedUnselectedImage:
    
    0 讨论(0)
提交回复
热议问题