Customizing UITabbar idea ? - ios

I read many posts on customizing color of selected tabbar item which is actually blue by default.
My idea was to put an UIImageView on each of my button.
Once the user select one button, I would then display the image (which is the same icon but with another colour as a gradient).
What do you think about that ?
Thanks in advance

You could always use this http://idevrecipes.com/2011/01/04/how-does-the-twitter-iphone-app-implement-a-custom-tab-bar/ and change it to include text and modify the colour.

Thankfully, iOS 5 introduced an appearance proxy allowing customisation of most basic UI elements, including the trusty UITabBar. The proxy is used to change ALL instances of a class throughout an application. However, with this came some basic properties available for specific instances.
See the selectedImageTintColor property of UITabBar for your needs.
Other appearance additions for this class are tintColor, backgroundImage and selectionIndicatorImage.

Related

How to change UIPickerView's selected tint color in iOS 14?

One of iOS 14's changes included changing the UIPickerView to have a light gray selected row tint color. I was wondering if there is any way to change this or even access this property. I looked in the storyboard's attributes inspector and there didn't seem to be anything. Same with the code, autocomplete didn't bring up any selected tint related properties. Also looked around the internet but since it is a relatively new feature there wasn't anything helpful. Before iOS 14 I could put a UIView with my chosen color underneath to simulate this, but this update takes that away as the gray is still visible, and it looks bad. Here's a pic:
https://i.stack.imgur.com/BmoNO.png
I was wondering if there are any real ways to do this.
Also, a good solution would be to disable the light gray, because then I could use the strategy I show above. Any tips?
Without more information I can't say for sure, but in your View Controller class, access the UIPickerView and you can change it's tintColor and isOpaque properties. Something like this I would imagine.
pickerView.isOpaque = false
pickerView.tintColor = .clear
I looked into subviews. On delegate of a UIPickerView, within method didSelectRow I was able to set background.
pickerView.subviews.last?.backgroundColor = .clear

How to prevent using UIAppearance with UIView's tintColor from changing all UITabBar icon colours?

If I perform UIView.appearance().tintColor = ... the tintColor of all the icons in the tab bar change from the normal inactive grey state to whatever I set the tint color to.
I don't understand why this is the case. I'm just changing the tint color of the app, and by default the tint color doesn't mess with making all the tab bar icons look active at once.
How do I stop it from doing this? I want the tint color to change, but the unselected tabs to retain an inactive color.
I hope you've found a solution by now, but here's my two cents anyway.
Interface Builder doesn't use the UIAppearance API anywhere (as far as I am aware). It does, however, set properties on certain objects, to be applied to them as they're instantiated.
There is a "Global Tint" property in the File Inspector which controls the top-level default tintColor. It is worth noting that, unless explicitly told a different color to use (whether via UIView.appearance() or just UIView.tintColor) child views inherit their tintColor from their parent views. Remember, this chain continues up through the view hierarchy until it hits something that has a tintColor. Usually, it's the UIWindow it ends up hitting, and that has the default blue color of which Apple is so fond. Any dimming or temporary recoloring for state is inherited either from the view itself, or a close ancestor. This is important to note.
It is also good to note that you can respond to this in UIViewController by overriding the tintColorChanged() method, which gets called whenever this happens. By messing with UIView.appearance(), you effectively disable the chain of inheritance for every view in the hierarchy, and you let each fend for itself for its own colors. In my mind, there are at least two ways that this might prevent a UITabBar from properly representing a tab's state:
First, the tab bar has tinted image views under the hood, which inherit their tint color from the parent UITabBar. Even if they could get state-specific colors from the tab bar, the poor thing wouldn't have anything different to tell them, other than, "You were given a color, and you will respect that color!", followed by a slap and a sound flogging, at which point they would sulk back, knowing no more than before. By disabling the hierarchical tintColor inheritance system, you disable state. That's not good. Don't do that.
Second, by setting the tint color for every UIView regardless of state, you have told the tab bar items to hold that color regardless of state. That's not good. Don't do that either.
If you're using Interface Builder (or Storyboards if you prefer), I'd recommend setting that global tint color in the File Inspector, and leaving it at that. This would still set your tint color the way you want, while saving these poor views from domestic abuse.
If you need screenshots of where to find the File Inspector or the Global Tint option, I'd suggest poking around that sidebar on the right in Xcode. A little poking around never hurt anybody (except in movies).
What do you mean when you say you're "changing the tint color of the app"?
The UIView appearance proxy is doing exactly what you told it to. You asked it to set the tintColor of ALL UIViews in your app, which includes those views inside your UITabBar.
It sounds like you don't actually want to alter the tintColor of all UIViews, but instead want to target a specific subset. You should look into appearanceForTraitCollection or the (now deprecated) appearanceWhenContainedIn methods.

iOS) How to add a divider(==separator) between tabbarItems

I searched this question many times but couldn't get enough information.
So I will use UIButton or UIView to replace UITabbar for customizing issue.
I want to put divider(separator) between two tabbarItems and bottom lines like the image below
But What I made now is below:
How can I make it as I want?
I did customize many view components(UIViewcontroller, UIButton, UITextfiled,UITableViewCell,UICollectionViewCell) but I don't know how to customize tabbarItem
I'm afraid there is no specific option to set a divider in UITabBar. But you can always use a custom tab bar. You can check this out, it has a special property for seperator image:
NMBottomTabBarController for iOS
There is also another option. You may like this :) I also used it myself in one of my app. I made an image that looks like a tab bar with seperator as a background image. Then put the items on it. Easy peasy. For example check this image:
Image Link
I hope this helps.

Make custom selected tab bar Item in iOS Swift

I am working on an application using Swift which needs to have a TabBarController and when user will select a tab then that particular tab bar item shows a 3d visual effect (Although it will be an static image I guess) which contains shadow and that tab bar item will be bigger in size as well with different tint colour.
Please see the attached image.
I have searched a lot on internet but no luck. Please someone help :(
Use http://cocoapods.org/pods/M13InfiniteTabBar
For as much as I do not like answers in the tone It can't be done, I feel that the specific of your screenshot, namely going outside of the UITabbar background, can't be done with UITabBarController.
You can use -initWithTitle:image:selectedImage:. Documentation found here

How to update default badge UI appearance in UITabbarController?

As displayed above, default badge appears in red and white color. Can we change its color scheme and customize that view?
The only solution I found was, creating entire UITabbarController as custom control. Can't I use default control and only update badge or provide custom UI to badge?
You could just create view(UIButton for example.) with the color (or background image) and text you want and add that to the tabbar on the place you want. But I think that would be some kind dirty implementation... Coz, you need to calculate the frame according to how many UITabbarItems you have. Otherwise, custom tabbar controller is the way to go :) I don't think customization of the default badge is possible. Good Luck!
I couldn't find any way to create custom badge for UITabBarItem. The only way to achieve this is to use custom UIButton/UIViews.

Resources