How to make UITabBar NOT translucent while using iOS 13 Dark Mode? - ios

When I set the background color of a UITabBar iOS automatically lightens this color since the default UITabBar is translucent.
But I would like to use a UITabBar which is NOT translucent. In iOS 12 and below I solved this by setting a background image of the desired color:
// Create an image from a given color using a custom extension
[[UITabBar appearance] setBackgroundImage:[UIImage colorImageWithColor:[UIColor redColor]]];
This works fine. However, I would like to use the new Dark Mode in iOS 13. Obviously this cannot be done when using a colored background image instead of a background color. Instead not without reacting manually to the appearance change to switch to another color image.
Using named colors would be way better IF it would be possible to tell iOS not to draw the `UITabBar translucent.
If I try to disable the translucent effect the UITabBar become all white instead of the specified color.
[[UITabBar appearance] setTranslucent:false];
How to solve this?

I managed to solve the problem using a custom UITabBar subclass.
When the app launches the dynamic color MyDynamicTabBarBG is set as non-translucent background by creating an image from this color
Changes between Normal and Dark Mode while the app is active are detected using traitCollectionDidChange. Than the dynamic color is simply re-applied by creating a new image.
Code:
#implementation MCTabBar
- (void)awakeFromNib {
[super awakeFromNib];
// Create a color image from a given color using a custom extension
[self setBackgroundImage:[UIImage colorImageWithColor:[UIColor colorNamed:#"MyDynamicTabBarBG"]]];
}
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
[self setBackgroundImage:[UIImage colorImageWithColor:[UIColor colorNamed:#"MyDynamicTabBarBG"]]];
}
#end
This works but is quite hacky. Is there really no more elegant solution?

Related

Changing the Navigation Bar Tint changes the color not correctly

I tried doing it like described in How to change Navigation Bar color in iOS 7? but unfortunatley it does not seem to work for me.
The color only changes to a light version. Since a screenshot describes it better than a thousand words here you go:
use this code work for me
[[UINavigationBar appearance]setBarTintColor:[UIColor colorWithRed:95/255.f green:154/255.f blue:201/255.f alpha:1]];
using storyboard

How to change a particular image in ios using appearance proxy?

I am using theme concept in iOS.I am changing the background of each
UIViewController for that i have used an UIImageView as background for all view controllers.Now on theme change i want to change the image but in this case other UIImageView in the view controller are also changed.So i want to know how can i change the particular image view using appearance proxy.
Code for changing the appearance using proxy
[[UIImageView appearanceWhenContainedIn:[UpdateProfile class], nil] setImage:image];

how to change ui componts color according to iOS theme?

I am very new to iOS.I want to set the theme for my iOS app & according to theme i am changing the background image.I also want to change the color of other ui component according to background image.I have one way of doing it by saving value in UserDefaults & check for every UI Component that would be very lengthy process.Is there any kind of other simple way of doing it in iOS?
You can take advantage of appearance proxy. Most of UIKit components have an appearance proxy object.
Let's take for example a navigation bar.
You can have this code.
UIColor *barColor = [UIColor redColor];
[[UINavigationBar appearance] setTintColor:barColor];
Once you execute this, all navigation bars across your app will have a red tint colour. You can customise other things and this way you set your theme globally.

Remove gradient/Gloss from UITabBarItem

I am customizing the UITabBar. I used my custom image in UITabBarItem. The problem is whether there is a gradient/gloss on the item. I checked Apple's app Store didn't had any of this glossy effect on its UITabBarItem. How can i remove gradient from UITabBarItem?
You just need to put clear image as `yourImage', it may help you
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage {yourImage}]]
Edit
i just googled it and found lot of similar questions. You can also try below code of lines
[[UITabBar appearance] setShadowImage:[UIImage imageNamed:#"Tappbarimage.png"]];
You'll have to provide the images yourself to the UITabBarItem with using this tabbarMethod setFinishedSelectedImage:withFinishedUnselectedImage:.
There's no other way to affect the processing it does to the images besides changing the color of the gradient with UITabBar's selectedImageTintColor appearance property.

How should I accomplish "setTintColor forState" (which does not exsist)?

In my app delegate I have this:
UIColor* color = [UIColor colorWithRed:36/255.0f green:38/255.0f blue:56/255.0f alpha:1.0f];
[[UIBarButtonItem appearance] setTintColor:color];
I'd like to have another color set for the pressed state.
How do I achieve this without using a background image?
The UIBarButtonItem don't have different states. However the UIButton do. So you might want to put an ordinary Button in your navigation bar or toolbar and then use different background images per state, which is possible for UIButton or you use the Highlight Tint property if you just want to change the tint for the highlighted state.
If you use an image for the different states, then you get to define an image for those states:
Default
Highlighted
Selected
Disabled
See this SO post: UIButton as UINavigationbar button

Resources