如何更改UITabBar的背景颜色?

huangapple go评论51阅读模式
英文:

How to change UITabBar background color?

问题

我一直在跟着教程,似乎当教程作者设置选项卡栏时,它会自动具有颜色。

这个教程是在不同的Xcode版本中制作的,所以可能这就是显示不同结果的原因。

正如您所看到的,背景颜色和选项卡栏的背景颜色是相同的。

我想要的是

我只是将选项卡栏的背景颜色设置为浅灰色。

这是应该这样做的方式,还是我漏掉了什么?

这就是我期望的结果。

英文:

I have been following tutorials and it seems that when the instructor set up the tabbar, it automatically has color.
This tutorials was made in different xcode version, so It could be why it shows the different result.

如何更改UITabBar的背景颜色?

As you can see, the background color and the tabbar background color is the same.

What I want is

如何更改UITabBar的背景颜色?

I just put the tabbar background color to light gray.
Is this how it is supposed to be done or am I missing something?

如何更改UITabBar的背景颜色?
This is what I am expecting

答案1

得分: 1

在viewDidLoad()方法中添加:

let backgroundColor = UIColor.gray
if let tabBar = self.tabBarController?.tabBar {
    tabBar.barTintColor = backgroundColor
}
英文:

In viewDidLoad(), add:

let backgroundColor = UIColor.gray
if let tabBar = self.tabBarController?.tabBar {
    tabBar.barTintColor = backgroundColor
}

huangapple
  • 本文由 发表于 2023年5月25日 22:05:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76333198.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定