0

Trying to use my custom color in my tabview.

Looking at this now, but they only said the option for system colors, and I have created a custom color called "Bg", how can I call it? This is what they suggested:

init() {
    UITabBar.appearance().backgroundColor = UIColor.blue
}

When I try to replace UIColor.blue for Color("Bg") I get an error.

ElKePoN
  • 822
  • 11
  • 21

1 Answers1

0
init() {
    UITabBar.appearance().barTintColor = UIColor(Color("bg")) 
}
Harshil Patel
  • 1,318
  • 1
  • 7
  • 26
  • How can I do it without the extension? I think creating an extension for 1 color is not a good idea. Also the naming is just an example, not my real color name :) – ElKePoN Dec 27 '20 at 02:18
  • It works but the background looks faded, I'll take a screenshot – ElKePoN Dec 27 '20 at 02:37
  • Look, it looks horrible lol https://i.postimg.cc/7Z7P89PZ/IMG-CD2247658-FA3-1.png. It's like the yellow goes above the text and icons instead of going into the background – ElKePoN Dec 27 '20 at 02:41
  • Now it displays correct, by the it seems I don't need the extension, only with `UITabBar.appearance().barTintColor = UIColor(Color("Bg"))` in the init did the trick – ElKePoN Dec 27 '20 at 02:50
  • Wops, there is a flag when I used the multitask to switch to another app and came back the color disappeared, it seems the color in the init won't work :/ – ElKePoN Dec 27 '20 at 02:54
  • Maybe it was a bug, or it could be that I added: `UITabBar.appearance().isTranslucent = false` which you could add to your answer – ElKePoN Dec 27 '20 at 02:58