Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Launch Storyboard: How can I change a Tab Bar's tint color?

What I'm doing:

Using a 'launch storyboard'. It's quite simple, and contains a default UITabBarController. I've set the tab bar's 'tintColor' to red in the launch storyboard, as well as in my app. I'm using Xcode 7, iOS 9.

What doesn't work:

The launch screen loads the tab bar using the default blue iOS tint color...! Then after loading, the tint color switches to red when the launch screen storyboard is replaced.


How on earth are you meant to set a tab bar's tint color in a storyboard?

Demo Project: http://s000.tinyupload.com/?file_id=73998115878034693063

like image 731
Jordan Smith Avatar asked Mar 02 '16 21:03

Jordan Smith


People also ask

How do I change the color of a tab bar in Swift?

backgroundColor = UIColor(red:1, green:0, blue:0, alpha:1) / UITabBar. appearance(). tintColor = UIColor(red: 1, green: 0, blue: 0, alpha: 1) // New!! func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {...}

What is IOS tint color?

tintColor is a variable in UIView that returns a color. The color returned is the first non-default value in the receiver's superview chain (starting with itself). If no non-default value is found, a system-defined color is returned (the shiny blue you always see).


2 Answers

The right way to go is to confuse Xcode. Xcode should not know that the launch storyboard that is used is actually a launch storyboard. This way you would be able to set some custom User Defined Runtime Attributes. However, you still would NOT be able to run some custom code...

So... To do this, follow these steps:

  1. Create a new Xcode project

  2. Copy your Main.storyboard into desktop and rename it to CustomLaunchScreen.storyboard.

  3. Add this CustomLaunchScreen.storyboard to the project.

  4. Open your Info.plist file and change key Launch screen interface file base name value from LaunchScreen to CustomLaunchScreen.

  5. Open your CustomLaunchScreen.storyboard. Delete the default UIViewController and set the UITabBarController as your initial view controller.

  6. Open the tabBar property of your UITabBarController and navigate to User Defined Runtime Attributes

  7. Add the tintColor property, set type as Color and set some custom value.

You can also watch a full video tutorial Here

like image 135
OlDor Avatar answered Oct 15 '22 17:10

OlDor


Well thanks to @OIDor for his solution, it is a great hack.

To be clear however, you don't need to do all that. All you have to do is:

  1. Edit the source of your Launch Screen storyboard and change launchScreen="YES" to launchScreen="NO", this enables you to do the next part...
  2. Add the user-defined attribute tintColor on the Tab Bar in the storyboard. This is not permitted by Xcode without the first step

Hey presto it's all working.

like image 1
Marc Palmer Avatar answered Oct 15 '22 19:10

Marc Palmer