我正在尝试将标签栏设置为在每个视图控制器上具有不同的背景图像。
class CharacterVC: UIViewController { var tabBarApparence = UITabBar.appearance() override func viewDidLoad() { super.viewDidLoad() tabBarApparence.backgroundImage = UIImage(named: "BlueTB") //Loaded from Image Asset }这工作正常,并在该视图中将其更改为蓝色,但是当我转到下一个视图时,它保持蓝色并且不会更改为我使用此代码编程的红色:
class AnonVC: UIViewController { var tabBarApparence = UITabBar.appearance() override func viewDidLoad() { super.viewDidLoad() tabBarApparence.backgroundImage = UIImage(named: "RedTabBar") // addtional code here }我有另外2个视图控制器,一个应显示图像的绿色版本,另一个应显示图像的紫色版本。
有什么建议可以解决这个问题?
I'm trying to set the tab bar to have a different background image on each view controller.
class CharacterVC: UIViewController { var tabBarApparence = UITabBar.appearance() override func viewDidLoad() { super.viewDidLoad() tabBarApparence.backgroundImage = UIImage(named: "BlueTB") //Loaded from Image Asset }This works fine and changes it to blue in that view, however when I go to the next view it stays the blue colour and doesn't change to the red colour which I programmed in with this code:
class AnonVC: UIViewController { var tabBarApparence = UITabBar.appearance() override func viewDidLoad() { super.viewDidLoad() tabBarApparence.backgroundImage = UIImage(named: "RedTabBar") // addtional code here }I have an additional 2 view controllers, one should display the green version of the image and the other the purple version of the image.
Any suggestions which could fix this?
最满意答案
如果要在视图控制器中更改TabBar的外观非常容易。 你可以在函数viewDidLoad或viewWillAppear中使用它。 代码是下一个:
// Set color of titles and icons in tabBar self.tabBarController?.tabBar.tintColor = UIColor.redColor() // Set color of background tabBar self.tabBarController?.tabBar.barTintColor = UIColor.blueColor()If you want to change appearance of TabBar in a view controller is very easy. You can this in function viewDidLoad or viewWillAppear. The code is the next:
// Set color of titles and icons in tabBar self.tabBarController?.tabBar.tintColor = UIColor.redColor() // Set color of background tabBar self.tabBarController?.tabBar.barTintColor = UIColor.blueColor()更多推荐
发布评论