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.
Related
So I have an app with four tabs.
The language on the tabs (danish) are different from the one on my phone (English).
Handling accessibility in the app, this is of course a case I'd like to handle.
And it works everywhere in the app except for the tab bar items.
Buttons, labels etc. are being read properly in danish, when setting someItem.accessibilityLanguage or someLabel.accessibilityLanguage.
When I'm trying to do the same with the tab bar items, nothing seems to work.
I've tried view.tabBarItem.accessibilityLanguage = "da" + setting .accessibilityLanguage on the view itself, the tabBarController, the tabBar and even the navigationController that the view is added to.
Is this intended behaviour from Apple? A bug? Or am I doing something wrong?
When setting view.tabBarItem.accessibilityLabel to various texts it works. So it's definitely registering my changes and not just reading the title that is set for the actual label on the tab bar item.
Is it possible to add a custom view below the navigationBar title, such that navigation bar preserves the default translucent effect and also adjust its height to accommodate the custom view?
Apple is doing it in Health App, App Store Connect App and Also in Calendar App.
I have gone through the Sample Provided by Apple:
Customizing Your App’s Navigation Bar.
but it doesn't provide any help.
Found an archived sample code: NavBar: Customizing UINavigationBar's appearance
It has a sample image which shows that a label is added below the title and is also a part of navigationBar but after running the sample project I checked that there is no way to even replicate that.
According to an answer to this similar question:
Adding custom view as title view and setting the prompt text doesn't give ability to change the prompt text font which looks weird.
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...
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.
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]