I have implemented three tab bar view controllers for my app. Each tab has collection views, And I have implemented following code in my ViewController to change tab bar image icon from stroke to fill on respective tab bar selection. I am using System Icons (SF Symbols).
My Code:
Error that I am getting at AppDelegate is: "Directly modifying a tab bar managed by a tab bar controller is not allowed."
How to solve this?
My Code:
Code Block self.tabBarController?.tabBar.items?[0] = UITabBarItem(title: "Myanmar", image: UIImage(systemName: "m.square.fill"), selectedImage: UIImage(systemName: "m.square")) self.tabBarController?.tabBar.items?[1] = UITabBarItem(title: "Singapore", image: UIImage(systemName: "s.square"), selectedImage: UIImage(systemName: "s.square.fill")) self.tabBarController?.tabBar.items?[2] = UITabBarItem(title: "Hyderabad", image: UIImage(systemName: "h.square"), selectedImage: UIImage(systemName: "h.square.fill"))
Error that I am getting at AppDelegate is: "Directly modifying a tab bar managed by a tab bar controller is not allowed."
How to solve this?
You can modify the properties of each UITabBarItem:
Code Block if let tabBarItem1 = self.tabBarController?.tabBar.items?[0] { tabBarItem1.title = "Myanmar" tabBarItem1.image = UIImage(systemName: "m.square.fill") tabBarItem1.selectedImage = UIImage(systemName: "m.square") } if let tabBarItem2 = self.tabBarController?.tabBar.items?[1] { tabBarItem2.title = "Singapore" tabBarItem2.image = UIImage(systemName: "s.square.fill") tabBarItem2.selectedImage = UIImage(systemName: "s.square") } if let tabBarItem3 = self.tabBarController?.tabBar.items?[2] { tabBarItem3.title = "Hyderabad" tabBarItem3.image = UIImage(systemName: "h.square.fill") tabBarItem3.selectedImage = UIImage(systemName: "h.square") }