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

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

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:
Create a new Xcode project
Copy your Main.storyboard into desktop and rename it to CustomLaunchScreen.storyboard.
Add this CustomLaunchScreen.storyboard to the project.
Open your Info.plist file and change key Launch screen interface file base name value from LaunchScreen to CustomLaunchScreen.
Open your CustomLaunchScreen.storyboard. Delete the default UIViewController and set the UITabBarController as your initial view controller.
Open the tabBar property of your UITabBarController and navigate to User Defined Runtime Attributes
Add the tintColor property, set type as Color and set some custom value.
You can also watch a full video tutorial Here

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:
Edit the source of your Launch Screen storyboard and change
launchScreen="YES" to launchScreen="NO", this enables you to do the
next part...
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.

I think I've figured this out.
There are quite a few blog posts online about how Launch Storyboards work, but not a lot from Apple. I found from this blog post which discussed that the launch screen images are captured at runtime from the launch storyboard. Digging into my simulator directory revealed that they were in fact there:
I'm not sure why, but the call to set the UITabBar's tintColor does not fire in time when the launch storyboard has loaded, but setting colors for other values such as the barTintColor property works:
All I can say is this: setting the tintColor on a UITabBar on a view controller in a launch storyboard is not supported. There is something going on behind-the-scenes when the launch storyboard is loaded preventing this from working.
TL;DR: you can't do this with a Launch Storyboard. For a workaround that tricks Xcode into treating your launch storyboard as a regular storyboard, see OlDor's answer.
As an alternative, you could take a screenshot of your app with the tab bar loaded properly, tweak it, and use that in a UIImageView on your launch view controller.
If you want to add just the tab bar without any currently selected tabs, add a UITabBar to your launch UIViewController and style the UITabBarItems to your liking:
This UITabBar has two UITabBarItems which can be styled without adding outlets to their view controllers.

Related

Navigation icon is not showing in ios11 with xcode9?

I have installed my existing application in ios11 using xcode8 the navigation bar icons are displaying as expected when app is run using xcode9 the navigation bar icons are not showing but click actions are working fine. any icons in Navigation bar are missing while navigating from one controller to another controller.
If the navigation icons are not showing, but the interaction is still exists and works properly, it seems, that the problem is with image of the BarButtonItem. You can do next:
1) Try to set a system icon for BarButtonItem
2) Look at assets and fill all three resolutions (1, #2x, #3x)
3) Check the color of BarButtonItem
4) Check View Hierarchy
This issue happened to me and it was related to the ViewController segue properties. The segue kind was set to "Show Detail(e.g. Replace)" and changing it to Show(e.g. Push) did the trick. This is very weird because it used to work well on previous versions of Xcode but not on Xcode 9.3
Hope that helps!
Main Story board pics:
change the "kind" attribute from this:
to this:

iOS 10 selected TabBarItem disappears

I have an app that uses TabBar based navigation inside a storyboard to navigate to different views.
The app worked fine from iOS7 - iOS9. But with iOS10 the tab item disappears when it gets selected (icon and title).
The tab bar is completely configured in the story board, no custom user code. In XCode everything looks fine:
But when the app is run on a iOS10 device/simulator the app looks like the following (the image shows different selections in the same tabbar, the behavior is the same for all 3 items)
What could be the cause for this issue? Are there any work arounds?
I finally found a solution to this issue. I am still not sure if this is due to a change or a bug in iOS 10.
Taken from this reply to an old question:
https://stackoverflow.com/a/39884669/1567923
You need to create a custom TabBarViewController and use it in your storyboard.
And in that view controller do something like that, to set the tintColor in code directly:
class UIMeeetTabBarController: UITabBarController, UITabBarControllerDelegate{
override func viewDidLoad() {
super.viewDidLoad()
self.tabBar.tintColor = Style.colorRed
}
I hope this will work for you too.
Select your tabbar from tabbarController scene and set some tintColor under the view and then check if it works!
You don't need to set up a custom tab-bar controller. The problem here is missing documentation (for which I filed a bug report with Apple and encourage you to do the same).
You can fix this in Interface Builder by selecting the tab bar itself and then going to the "Tab Bar" (top) section of the Attributes inspector and setting the "Image Tint" color. I presume that when a tab-bar item enters the "selected" state, the control inverts the alpha channel of the graphic and lets the color of the underlying tab bar show through. If that color is "clear" or matches your tab-bar item's background exactly... you see nothing. If you have a dark background, try setting this value to white.
The graphic for tab-bar items is displayed using only its alpha (non-transparent) pixels as a black-&-white image. These pixels will then allow the "tint" of the underlying tab bar to show through or not, depending on the unselected/selected state.
I know this is an old one, but I faced the same issue in Xcode 9, and finally solved it without a single line of code. Go to the Attributes Inspector and make the Tab Bar Item Selected Image match the Bar Item Image...

UITabBarController storyboard launch screen - initial tab?

I'm using a storyboard as my launch screen in my app, it contains a UITabBarController with 5 UINavigationControllers. The storyboard doesn't do anything but provide launch screens.
What I want to do is change the default selected tab. I'm currently stuck with this:
And once the actual view controllers load I get this:
As you can imagine it's a bit jarring to have the selection jump like it does. I don't know how to change the tab programmatically since I cannot attach a custom class to anything in a launch screen. Of course, I don't really care if I do it for real, if there's a way to fake it with icons of different colors, that's fine as well, but the system adds that tint to selected icon.
Is there a way to do this with a storyboard launch screen? Thanks.
Don't use a tab bar controller in your LaunchScreen.storyboard. Instead use a normal view controller and add a tab bar, then add tab bar items as required. That seems to be the only way to make a tab bar without any index selected.
Though this question was asked years ago, I've wrangled with it quite a bit and figured out a workaround that I'm satisfied with for my app TimeFinder.
The other answers here have made some good suggestions, but trying to build a replica of TabBarController sounds challenging and unsustainable, and I didn't have much luck with the User Defined Attributes hack mentioned by Akshay Agrawal 1.
Since the problem is ultimately that the wrong item is shown as selected in the launch screen, I decided to hide the selection entirely by changing the selected image tint color to light gray to match the color of the other unselected tab bar item icons 2.
This allowed me to copy and paste my project's top-level view controllers (view controllers embedded in navbarcontrollers embedded in a tabbarcontroller) into the Launch Screen storyboard, delete all the inessential connections and view controllers, and end up with a quality launch screen that makes the app appear to load faster than it does.
Here's my Launch Screen storyboard for reference 3, and here is my app which will have this launch screen update shortly 4.
TimeFinder on the App Store
Use this piece of code in your view will appear method.
yourTabBarController.selectedViewController=[yourTabBarController.viewControllers objectAtIndex:2]

navigation & tab bars black for a split second right after launch

When launching or bringing my app from the background the navigation bar & tab bar are black for a split second before assuming storyboard defaults.
I feel there is somewhere a property enforcing this but I can't seem to find it.
Found something in the project properties info tab under "Custom iOS Target Properties"
where NavigationBar.Style = Default and NavigationBar.Translucent = NO which seem fine and don't affect the result.
It started happening around the iOS8 upgrade but can't time it very precisely.
Anyone has a clue on what might be causing this? Or where we set
Your view controllers of tab bar should be subclassed with UIViewController not UITabBarViewController. Please check your header file

iOS - Set UITabBar Icons

I've checked a couple of solutions, saw you can set it in the storyboard but to set the icon you have to set it as a default identifier, and doing so removes the title and sets the default one, if you set the title to your own title it reverts to custom and no icon image once again.
I'd like to use the default iOS icon images for this, instead of downloading some images off the web.
I also tried to set it up in the AppDelegate in didFinishLaunching by getting the TabBar by accessing the rootViewController, but it gives me an undefined selector error when setting the tab bar items. What does seem to work is setting the tabBarItem property in my view controllers, but this way only one is set when the view shows and I want them both to be set already, also same issue as with the identifier in storyboard, it sets the default title of the icon.
It's against the iOS HIG to use the system-provided tab bar icons with non-standard titles. It's not a good idea because the icon/title combinations are part of the common UI language that users come to expect.
So you won't find a way in the standard APIs to set system-provided tab bar icons without also setting the corresponding standard titles.

Resources