Set TabBar Item Disabled Color - ios

My Current tabBar :
Expected tabbar with disabled tabs(ignore the language its for sample purpose):
I am able to disable items from my first tab bar image by using this :
self.isEnabled = false
For Not loggedin users i disabled these items but i want to change their color to something dull. How to do that.
Note : I am not asking for changing color in unselected state. I am asking only for the disabled state.

Add your following tab bar images as white.
Like
And in you MainStoryboard select your Main TabBarController, then change the image tint to Red (whatever color you need to show the image color)
Then you can see that the unselected TabBar Items color looks disabled.

To make look like disabled tabbar item.
if let arrayOfTabBarItems = tabBarViewController.tabBar.items as! AnyObject as? NSArray,tabBarItem = arrayOfTabBarItems[2] as? UITabBarItem {
tabBarItem.enabled = false
}

Related

Bar section in iOS is extended unnecessarily

In the image shared, the orange section is the bar section , which is having unnecessary height, I am not able to resolve this issue by myself.
the views are like this
Parent Controller = View Controller
Child views = green view, black tableview
Please help to correct the height of the orange bar.
Seems like you have enabled prefersLargeTitles.
Make it false in your viewWillAppear()
self.navigationController?.navigationBar.prefersLargeTitles = false
You can also disable it from the storyboard.
Select your Navigation Controller -> Navigation Bar -> Uncheck prefers large titles
it seems like you're using the largeTitles on the navigationBar,
var prefersLargeTitles: Bool { get set }
When this property is set to true, the navigation bar allows the
title to be displayed out-of-line and using a larger font. The
navigation item used to build the bar must specify whether it wants
its title displayed in the large or small format. Use the
largeTitleDisplayMode property to configure the title's appearance.
When the property is set to false, the navigation bar displays the
title inline with the other bar button items.
try to disable it by:
navigationController?.navigationBar.prefersLargeTitles = false
or you can do this as well:
navigationItem.largeTitleDisplayMode = .never
hope this helps:)
https://developer.apple.com/documentation/uikit/uinavigationbar/2908999-preferslargetitles

How to select tab bar item without selecting it

I am using swift and I have a problem with the tab bar. I want to select a tab bar item, but without open it, what I mean: I want to change its color like it is selected but without the selection is it possible to be done. Here is a image: https://imgur.com/a/IdPituS , I want the top left item (burger menu item) color to be like the first one and the first one color to be light (like not selected).
Try to edit the image of the item you want to highlight (selecting without selecting).
You can try something like this:
let image = shouldHighlight ? UIImage(named: "highlightItem") : UIImage(named: "normalStyle")
myViewController.tabBarItem = UITabBarItem(title: "text", image: image, selectedImage: UIImage(named: "selectedImage"))
Then you update the viewControllers property in you tab bar viewController
myTabViewController.viewControllers
You can pre-select the tabBar item
like this:
tabBarController?.selectedIndex = 0 //select whatever You want
and
colorTint the unselected index
tabBar = UITabBarController()
tabBar?.tabBar.barTintColor = UIColor.white //bar Color
tabBar?.tabBar.tintColor = .red //Icons color
tabBar?.tabBar.unselectedItemTintColor = .white //Unselected item Colors

IOS - tab bar item image modifications

I want to change the default color of the tab bar item image to be the original color of the image (black) as opposed to a gray when it's not selected.
I also want to change the tab bar item image to a filled version once it's selected.
Last thing is the position.. It seems to expect text under it so it's not centered, how do I center it vertically and possibly make it smaller?
I'm currently setting it this way:
let profileNavController = UINavigationController(rootViewController: profileController)
profileNavController.tabBarItem.image = UIImage(named: "icon_tab_user")
This is how it looks selected and unselected:
From apple we know,
By default, the actual unselected and selected images are automatically created from the alpha values in the source images. To prevent system coloring, provide images with UIImageRenderingModeAlwaysOriginal.
Take a look here.
Changing tab bar item image and text color iOS
I was able to change the highlighted and unhighlighted images as well as the position with this:
let profileNavController = UINavigationController(rootViewController: profileController)
let profileTabBarItem = UITabBarItem(title: nil, image: UIImage(named: "icon_tab_user")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal), selectedImage: UIImage(named: "icon_tab_user_highlighted"))
profileTabBarItem.imageInsets = UIEdgeInsetsMake(5.5, 0, -5.5, 0)
profileNavController.tabBarItem = profileTabBarItem

Changing tintColor to default (blue) in NavBar

I can change the tintColor for my App (everywhere) in a setting pane.
When I change the tintColor, and after that try to return to the default tint color, some buttons in NavBar don't return to blue, how can I handle this?
To verify:
- create a new project Master/Detail
- In the detail view: add Two buttons, named: "Red Interface" and "Blue interface"
- In DetailViewController, add the actions
#IBAction func tapRed(sender: AnyObject) {
view.window!.tintColor = UIColor.redColor()
}
#IBAction func tapBlue(sender: AnyObject) {
view.window!.tintColor = nil
}
Now run the application, create a timestamp, go to detail, tap redInterface, then blue interface
That's OK in the Detail View, but when you return to Master, the "+" button item is red, not blue.
I can fix the problem by setting a real blue color instead of nil, but that's not a long term solution, if Apple change the default tintColor.
Is this a bug? Is there something I can do to bypass this problem?
A quick workaround would be to fetch the default tint color once on the initial app load and store it somewhere (i.e. in the user defaults)
From Apple's iOS 7 UI Transition Guide (Specifically under the Using Tint Color section).
By default, a view’s tint color is nil, which means that the view uses its parent’s tint. It also means that when you ask a view for its tint color, it always returns a color value, even if you haven’t set one.
That's a good workaround!
In fact, I don't even need to store the color.
If I change to
#IBAction func tapBlue(sender: AnyObject) {
view.window!.tintColor = UIButton(type:UIButtonType.System).titleColorForState(.Normal)
}
That gives me the correct blue color, even if I changed the tintColor (probably because I don't address a button in the view hierarchy)

Change image of UITabBarItem

I need to set a different image for the more button in the UITabBar in Swift 2.
I tried this but it doesn't work.
let more = tabBarController.moreNavigationController.tabBarItem
more.image = UIImage(named: "squadra")?.imageWithRenderingMode(.AlwaysOriginal)
Really thanks.
You can do it from interface builder as follows:
Open document outline and select tab bar item as follows:
Then change image property of bar item from attribute inspector to appropriate xcasset as follows:
Finally your image of tab bar item will be changed
tabBarController.tabBar.items?.first?.image = UIImage(named: "squadra")?.imageWithRenderingMode(.AlwaysOriginal)

Resources