UISplitView remove app tint color - ios

My app is based on a UISplitViewController on iPad.
There is a functionnality which add a second UISplitViewController over the first.
But this remove the apptint.
I've tried the following code in the first split view when going back on first split view, but it does not work:
-(void)viewWillAppear:(BOOL)animated {
UIWindow *appWindow = [[UIApplication sharedApplication]keyWindow];
[appWindow setTintColor:[UIColor redColor]];
}
I heard there is a bug (8276014 in apple bug report) that seems to match my issue.
Any help?

You can also set an app’s tint color in Interface Builder. The Global Tint menu in the Interface Builder Document section of the File inspector lets you open the Colors window or choose a specific color.
or
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window.tintColor = [UIColor redColor];
return YES;
}
or
In iOS 7, tint color is a property of UIView. iOS 7 apps often use a tint to define a key color that indicates interactivity and selection state for UI elements throughout the app.
When you specify a tint for a view, the tint is automatically propagated to all subviews in the view’s hierarchy. Because UIWindow inherits from UIView, you can specify a tint color for the entire app by setting the window’s tint property using code like this:
Setting the tintColor property by using the appearance proxy APIs is not supported in iOS 7.
[[UIView appearance] setTintColor:[UIColor redColor]];//iOS 6

Related

Initial app load tab bar tint blinking

When iOS application starts then all tab bar icons have default tint (light blue). I setup my own custom tint color in viewDidLoad. But it applies with delay and I see transition between default tint color and my custom tint color. How can I apply my custom tint color to tab bar before interface will appear and eliminate color blinking?
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
// Set the tint here after the view has been loaded completely
}
So this is because the default is set when the application finishes launching, and then is changed when your view controller is initialized. To do this, you want to change the tab bar tint globally.
Do this in your AppDelegate.m file in the - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method.
Use [[UITabBar appearance] setBarTintColor:(UIColor *)]; to set the tint of your tab bar across the entire application, where (UIColor *) is of course replaced by the color you want.
Hope this helps.

Prior iOS 7 tintColor without navigationBar background

I'm setting:
[self.window setTintColor:[UIColor redColor]];
In iOS 7 everything works ok - my navigationController.navigationBar is white (as I set it transparent) and all icons are colored to red. However in iOS 6 (where navigation bar is set NOT to be transparent) all icons are left with its original colors (eg blue). I can't find a way to color these images in iOS 6, is it possible?
To be more precise:
if (NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_6_1) {
[self.navigationBar setTintColor:[UIColor whiteColor]];
}
Now I get white navigation bar but also the titles and buttons are white - how to colour them?
Please go through the documentation(s) carefully.
UIWindow inherits from UIVIew and the tintColor property of UIView is not available prior to iOS7. From the source itself (UIView):
#property(nonatomic,retain) UIColor *tintColor NS_AVAILABLE_IOS(7_0);
It clearly defines this. So you cannot set this prior to iOS7.
You will have to set the navigationBar's tintColor (which became barTintColor in iOS7) to white. You might want to use the UIAppearance selector for changes to be reflected throughout your app.
EDIT:
All items in a UINavigationBar are UIBarButtonItems. You will have to set their own tintColors.

UIStatusBar setTranslucent:NO avoid moving content down

I am trying to get my UINavigationBar and UIStatusBar to be opaque and have no translucency properties whatsoever. I tried using [[UINavigationBar appearance] setTranslucent:NO]; but that moves the view content down a few pixels. I want that content to be under the UINavigationBar. Is there an easy way to do this?
I had the same problem when I used [[UINavigationBar appearance] setTranslucent:NO]; on AppDelegate.m . What worked for me: set "Under Opaque Bars" (see image) property in each ViewController scene under that opaque Navigation Bar
Try to change the following properties for your UIViewControllers for elimination pixels shift effect for iOS7.
First of all, translucent property just can't be set using UIAppearance. Next there is no relation between whether your bars are translucent or opaque & the changed positions of your pixels.
Customizing the Appearance of a Navigation Bar
In iOS 7, a navigation bar’s tintColor affects the color of the back indicator image, button titles, and button images. The barTintColor property affects the color of the bar itself. Additionally, navigation bars are translucent by default. Turning the translucency off or on does not affect buttons, since they do not have backgrounds.
In my IOS app, I need to do the following in - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions function
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"7.0")) {
[application setStatusBarStyle:UIStatusBarStyleLightContent];
self.window.clipsToBounds =YES;
self.window.frame = CGRectMake(0,20,self.window.frame.size.width,self.window.frame.size.height-20);
//Added on 19th Sep 2013
self.window.bounds = CGRectMake(0, 20, self.window.frame.size.width, self.window.frame.size.height);
}
There is a more detailed discussions here ios-7-status-bar-back-to-ios-6-style

How to get the blurred and translucent effect on a navigation bar in iOS 7?

Problem
My app appears to be laid out correctly, but I cannot achieve the blurry translucent effect that iOS 7 is famous for. Mine appears opaque.
Desired Effect
I'm trying to get a more obvious blur effect such as Apple's Trailers app:
Translucency
In my subclass of UINavigationController, I make the navigation bar translucent:
- (id)initWithRootViewController:(UIViewController *)rootViewController
{
if (self = [super initWithRootViewController:rootViewController]) {
self.navigationBar.translucent = YES;
}
return self;
}
Tint Color
In my subclass of UIApplicationDelegate, I set the tint color of the navigation bar. I discovered that the alpha of the tint color makes no difference. That is, using an alpha of 0.1 would not cause the bar to become more translucent.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UINavigationBar appearance] setTintColor:[UIColor greenColor]];
}
Edges
In my content view controller, I set the edge to UIRectEdgeNone so the top doesn't get chopped off by the navigation bar. If I were to use the default UIRectEdgeAll, the navigation bar would permanently cover the top of my content. Even if I were to live with this abnormality, UIRectEdgeAll still does not enable the translucency effect.
- (void) viewDidLoad
{
[super viewDidLoad];
self.edgesForExtendedLayout = UIRectEdgeNone;
}
Edit: Experimenting with Edges
Ad pointed out by #rmaddy in the comments, the problem may be with the edgesForExtendedLayout. I found a comprehensive tutorial edgesForExtendedLayout and attempted to implement it:
- (void) viewDidLoad
{
[super viewDidLoad];
self.edgesForExtendedLayout = UIRectEdgeAll;
self.automaticallyAdjustsScrollViewInsets = YES;
self.extendedLayoutIncludesOpaqueBars = NO;
}
It did not work. Firstly, there was no translucency effect. Secondly, the top of my content was chopped off. On the following example page with the above code, the avatar was initially covered by the navigation bar and it was very hard to scroll to. You could pull down to see the top of the avatar, but when you let go, the page would automatically bounce back up and the avatar would be obscured again.
The problem was caused by the third party pull-down-to-refresh view EGORefreshTableHeaderView, which was popularly used before iOS 6 introduced the system refresh control.
This view confuses iOS 7, making it think that the content is taller than it really is. For iOS 6 and 7, I've conditionally switched to using UIRefreshControl. Now the navigation bar will not chop off my content. I can use UIRectEdgeAll to make my content go underneath the navigation bar. Finally, I tint my navigation bar with a lower alpha to get the translucency effect.
// mostly redundant calls, because they're all default
self.edgesForExtendedLayout = UIRectEdgeAll;
self.automaticallyAdjustsScrollViewInsets = YES;
self.extendedLayoutIncludesOpaqueBars = NO;
[[UINavigationBar appearance] setTintColor:[UIColor colorWithWhite:0.0 alpha:0.5]];
If you need to achieve exactly the same effect as in the iTunes Store (Dark Blur).
Configure the barStyle attribute of the navigation bar as follows:
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;

iOS 7 : Disable UINavigationBar Translucency For Entire App

Is there a way to disable UINavigationBar Translucency for an entire application?
I'm aware that using [self.navigationController.navigationBar setTranslucent:NO] can fix this issue for a single controller, but I have a lot of UINavigationBars in my application and this is a pretty tedious solution.
I've tried [[UINavigationBar appearance] setTranslucent:NO], but that functionality is surprisingly not supported. Doing that results in Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** Illegal property type, c for appearance setter, _installAppearanceSwizzlesForSetter:'
If I HAVE to, I can go through my entire app setting UINavigationBars to disable translucency one by one, but there must be some more elegant solution to this issue...
if you set the translucence of the first navigation bar in the stack to false [self.navigationController.navigationBar setTranslucent:NO], it will reflect in all the following NavigationViewController that are pushed to that stack.
Here is a Swift solution if you want to apply this Styling to the whole app.
in the AppDelegate class add this to the didFinishLaunchingWithOptions:
For Swift 2:
UINavigationBar.appearance().translucent = false
For Swift 3+:
UINavigationBar.appearance().isTranslucent = false
It seems very simple with this code in appDelegate didFinishLaunchingWithOptions (works fine with iOS 8 and above versions)
[[UINavigationBar appearance] setTranslucent:NO];
I think you are right about no appearance proxy being available for this property. Are you using UINavigationControllers or UINavigationBar objects? If you are using UINavigationBars you could subclass it and create a non-translucent nav bar.
Header file:
#import <UIKit/UIKit.h>
#interface ABCNonTranslucentNavBar : UINavigationBar
#end
Implementation file:
#import "ABCNonTranslucentNavBar.h"
#implementation ABCNonTranslucentNavBar
- (void)drawRect:(CGRect)rect
{
[self setTranslucent:NO];
}
Then just replace the UINavigationBars with your subclass. You could also do something similar with a subclassed UINavigationController.
Adding this in case anyones still battling this.
You can fool it though by specifying a non exist image, which will make the nav bar INCLUDING it's tool bar go opaque
[[UIToolbar appearance] setBackgroundColor:[UIColor colorWithRed:219.0/255.0 green:67.0/255.0 blue:67.0/255.0 alpha:1.0]];
[[UIToolbar appearance] setBackgroundImage:[[UIImage alloc] init] forToolbarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
I know this is old, but this might come in handy for someone;
You can use a category, and within it* set the property [translucent][1]
#implementation UINavigationBar (MakeTranslucent)
-(void)willMoveToWindow:(UIWindow *)newWindow {
[super willMoveToWindow:newWindow];
self.translucent = NO;
}
#end
I used willMoveToWindow, I do not know whether this is a good idea so UAYOR.
See the excerpt from UIKit code documentation:
/*
New behavior on iOS 7.
Default is YES.
You may force an opaque background by setting the property to NO.
If the navigation bar has a custom background image, the default is inferred
from the alpha values of the image—YES if it has any pixel with alpha < 1.0
If you send setTranslucent:YES to a bar with an opaque custom background image
it will apply a system opacity less than 1.0 to the image.
If you send setTranslucent:NO to a bar with a translucent custom background image
it will provide an opaque background for the image using the bar's barTintColor if defined, or black
for UIBarStyleBlack or white for UIBarStyleDefault if barTintColor is nil.
*/
Correct Swift 4 solution is
UINavigationBar.appearance().isTranslucent = false
UINavigationBar.appearance().backgroundColor = .white
I think appearance api does not support translucent property of navigation bar .
But you can do this for whole App like this , please have a look at this code --
here Menu Screen is a root view controller .
MenuScreen *ms = [[MenuScreen alloc]initWithNibName:#"MenuScreen" bundle:nil];
UINavigationController *nv = [[UINavigationController alloc]initWithRootViewController:ms];
//This will set property for whole App.
[nv.navigationBar setTranslucent:NO];
self.window.rootViewController = nv ;
If you don't use storyboard, but IB, set the navigation bar style of your MainWindows.xib to NOT translucent and set as color not the clear color.

Resources