自定义每个视图控制器中的UITabBar.appearance [Swift](Customising the UITabBar.appearance in each View Controller

编程入门 行业动态 更新时间:2024-10-24 17:24:01
自定义每个视图控制器中的UITabBar.appearance [Swift](Customising the UITabBar.appearance in each View Controller [Swift])

我正在尝试将标签栏设置为在每个视图控制器上具有不同的背景图像。

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()

更多推荐

本文发布于:2023-08-01 04:19:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1354010.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   视图   器中   UITabBar   appearance

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!