UITabBar not showing selected item images in ios 7

后端 未结 20 1867
我在风中等你
我在风中等你 2020-11-29 18:36

The icons show fine in ios 6 but not in ios 7. I\'m setting the selected state in the viewController viewDidLoad method. When the user selects a tab bar item the image disap

20条回答
  •  长情又很酷
    2020-11-29 19:10

    Swift version of showing selected and unselected images and title with UIAppearance API In your Appdelegate.m copy following code if you have tab base app.following code assume you have 4 tab bar.

    let tabBarController: UITabBarController = (self.window!.rootViewController as! UITabBarController)
    
        let tabBar:UITabBar = tabBarController.tabBar
    
        let tabBarItem1:UITabBarItem = tabBar.items![0]
        let tabBarItem2:UITabBarItem = tabBar.items![1]
        let tabBarItem3:UITabBarItem = tabBar.items![2]
        let tabBarItem4:UITabBarItem = tabBar.items![3]
    
        tabBarItem1.title = "Home";
        tabBarItem2.title = "Maps";
        tabBarItem3.title = "My Plan";
        tabBarItem4.title = "Settings";
    
        tabBarItem1.selectedImage = UIImage(named: "home_selected.png")!
        tabBarItem2.selectedImage = UIImage(named: "maps_selected.png")!
        tabBarItem3.selectedImage = UIImage(named: "myplan_selected.png")!
        tabBarItem4.selectedImage = UIImage(named: "settings_selected.png")!
    
         tabBarItem1.image =  UIImage(named: "home.png")!
         tabBarItem2.image =  UIImage(named: "maps.png")!
         tabBarItem3.image =  UIImage(named: "myplan.png")!
         tabBarItem4.image =  UIImage(named: "settings.png")!
    
    
        let tabBarBackground: UIImage = UIImage(named: "tabbar.png")!
        UITabBar.appearance().backgroundImage = tabBarBackground
        UITabBar.appearance().selectionIndicatorImage = UIImage(named: "tabbar_selected.png")!
    
    
        UITabBarItem.appearance().setTitleTextAttributes([
            NSForegroundColorAttributeName : UIColor.whiteColor()
            ]
            , forState: .Normal)
        let titleHighlightedColor: UIColor = UIColor(red: 153 / 255.0, green: 192 / 255.0, blue: 48 / 255.0, alpha: 1.0)
        UITabBarItem.appearance().setTitleTextAttributes([
            NSForegroundColorAttributeName : titleHighlightedColor
            ]
            , forState: .Highlighted)
    

提交回复
热议问题