简体   繁体   中英

(Swift) selected tabBar Color?

I already know how to set tabBar's "barTintColor". What I want to know is how to set a specific color to selected tabBar(Like in the pic the tabBar which is selected is having dark pink color). Just like that.Thanks in advance :)

标签栏

Change the tintColor (that's all you are allowed to do)

Make a subclass of UITabBarController, set it as the class of your UITabBarViewController:

class myOwnTBC: UITabBarController {
  override func viewDidLoad() {
    super.viewDidLoad()
    self.tabBar.tintColor = .blueColor()
  }
}

After more research following your comment:

I do believe, Apple does not want a developer to change the backgroundcolor of the UITabBar. Please see Apple's Interface Guidelines concerning the TabBar . I quote from it:

A tab bar: Is translucent

I tried subclassing UITabBarItem and manipulate the background, which gave me the following Exception:

Directly modifying a tab bar managed by a tab bar Controller is not allowed

Solution?! You won't like it, but if you want to use a UITabBarController, you have to stick with the translucent preset.

Workaround? The only workaround I can think of at the Moment is: Create your own navigation using your own UIView-Subclass. This will violate the Interface Guidelines anyways, but you can reach your Goal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM