I can use this code to change the background color of the tab bar:
let appearance = UITabBarAppearance()
appearance.backgroundColor = UIColor(bgColor)
let appearance2 = UITabBar.appearance()
appearance2.scrollEdgeAppearance = appearance
appearance2.standardAppearance = appearance
But it seems this is a one-time thing. If I run this code again later with a different value of bgColor, it does not change. What can I do to modify the tab bar background color after I have set the color once? I need this because I am allowing the user to change it.