Remove Navigation Bar shadow Colour on iPhone 6/6plus - ios

I'm trying to remove this white stroke. I've previously fixed this using
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
and it work perfectly on iPhone 4s,5,5s and iOS 7/8. But for some reason on iPhone 6/6+ that whte shadow is still there.
I've also tried this to no result. It just makes the shadow a darker colour than my current navBar bgColour (white: 0 alpha 0.9).
UIView * bgView = [[UIView alloc] initWithFrame:CGRectMake(0, self.navigationController.navigationBar.height, self.navigationController.navigationBar.width, 1)];
bgView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.9];
[self.navigationController.navigationBar addSubview:bgView];
[self.navigationController.navigationBar setShadowImage:nil];
Any ideas?

Try doing the following, this at least works for me.
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
I also then set a custom colour
[[UINavigationBar appearance] setBarTintColor:[UIColor XXXXXX]];

Try to set navigation's bar property clipsToBounds to YES

Related

In Xcode 13 [[UINavigationBar appearance] setBarTintColor: not working properly?

I have updated my Xcode into 13, later on words in my old project navigation and tab bars colours was changed to transparent.
My Code is
[[UINavigationBar appearance] setBarTintColor:[UIColor AppThemeColour]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTranslucent:NO];
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
I tried to add background colour but title and images of the navigationBar not appering.
self.navigationController.navigationBar.backgroundColor = [UIColor bOneAppThemeColor];
[[UINavigationBar appearance] setBarTintColor:[UIColor AppThemeColour]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTranslucent:NO];
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
I have studied this below link but i'm unable to implement it in Objective C
https://developer.apple.com/forums/thread/682420
Almost everything you're doing is wrong (and has been wrong for several years). You need to use UINavigationBarAppearance (and UITabBarAppearance) and apply them to both the bar's standardAppearance and its scrollEdgeAppearance. Set the appearance's background color, not its tint color. And do not touch the translucent property ever.
In this simple example, we make all navigation bars adopt your theme color. Modify to suit your needs and desires:
if (#available(iOS 13.0, *)) {
UINavigationBarAppearance* appear = [UINavigationBarAppearance new];
appear.backgroundColor = [UIColor AppThemeColor];
id proxy = [UINavigationBar appearance];
[proxy setStandardAppearance: appear];
[proxy setScrollEdgeAppearance: appear];
} else {
// Fallback on earlier versions
}

Navigation Bar Appearance Settings don't apply constantly

I tried to customise my UINavigationBarController:
// Customize NavBar Appearance
[[UINavigationBar appearance] setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[UIImage new]];
[[UINavigationBar appearance] setBackgroundColor:[UIColor clearColor]];
[[UINavigationBar appearance] setTitleTextAttributes:#{NSForegroundColorAttributeName: [UIColor whiteColor],
NSFontAttributeName: [UIFont fontWithName:#"Lato-Light" size:35.0]}];
// Set NavBar Bottom Border to White by adding a view with height 1
UINavigationController *navBarController = [[self.tabBarController viewControllers] objectAtIndex:0];
CGFloat navBarWidth = navBarController.navigationBar.frame.size.width;
UIView *navBottomBorder = [[UIView alloc] initWithFrame:CGRectMake(0, kNavBarHeight- 1, navBarWidth, 1)];
[navBottomBorder setBackgroundColor:[UIColor colorWithWhite:255.0f alpha:0.25f]];
[navBottomBorder setOpaque:YES];
[[UINavigationBar appearance] addSubview:navBottomBorder];
The problem I encounter is, that this added subview randomly disappears when clicking through my tab bar items. Sometimes it is visible perfectly, sometimes only the appearance settings for text and font color are presented. By the way: These are always correct. Only my subview is not showing up anymore after the first boot and switching the tabs.
When I use "insertSubview" instead of "addSubview" it seems to work. So I could imagine, that the navbar is being drawn over my added subview?

Change UINavigationBar Tint Color

Hi I am trying to change the tint color of a newly created navigation bar but i am having difficulty getting the tint color to change and have tried various ways of implementing tintColor. Here is how I am creating it.
UINavigationBar *navBar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 64)];
[navBar setTintColor:[UIColor redColor]];
[settingsView addSubview:navBar];
Do I need to approach it differently or redraw it?
Can you try this,
[navBar setBarStyle:UIBarStyleBlackOpaque];
[navBar setTintColor:[UIColor redColor]];
iOS 7 Has a method called setBarTintColor which works perfectly
Worked perfectly for me!
[self.homeNavigationBar setBarTintColor:[UIColor whiteColor]];
Try this:
[[UINavigationBar appearance] setBarTintColor:[UIcolor redcolor]];
use this code
UIColor *appcolor=[UIColor colorWithRed:63.0/255.0 green:148.0/255.0 blue:246.0/255.0 alpha:1.0];
[[UINavigationBar appearance] setBarTintColor:[UIColor appcolor]];

iOS 7 tabBar-line, how to remove it?

Apple has added a tiny line over the tabBar in iOS 7 which is supposed to work as a shadow or fade between the tabBar and the UI
Since I am using a custom-made tabBar the line is quite irritating. How do you remove it? Please tell me it is possible, otherwise I need to redesign my whole app lol....
/ Regards
*Edit
Sloved my problem with the following line of code:
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
UIImage* tabBarBackground = [UIImage imageNamed:#"tabbar_bg.png"];
[[UITabBar appearance] setShadowImage:tabBarBackground];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
These code works pretty well for me (I don't really have background image for tab bar):
[tab_main.tabBar setBackgroundImage:[[UIImage alloc] init]];
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
And I use these code to add a frame too:
UIColor* color_green = UIColorFromRGB(0x348e5b);
tab_main.tabBar.layer.borderWidth = 0.50;
tab_main.tabBar.layer.borderColor = color_green.CGColor;
[[UITabBar appearance] setTintColor:color_green];
Hope that helps.
In iOS 8 the top border can be removed by setting the tab bar style to black in the inspector.
Swift
Nice simple solution:
Write this below code in your custom tab bar class. Then it will hide horizontal shadow line.
self.tabBar.setValue(true, forKey: "_hidesShadow")
Objective C
[self.tabBar setValue:#(YES) forKeyPath:#"_hidesShadow"];
self.tabBarController = [[UITabBarController alloc] init];
[[[self tabBarController] tabBar] setBackgroundImage:[UIImage imageNamed:#"YOURIMAGE.png"]];
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
I'm not seeing anything in the UITabBar API for affecting that separator, but if the separator is within the UITabBar (a UIView subclass), I'd expect you can insert a new one-pixel-high UIView on top of it. You'd have to grab a slice of the image that you want to appear there and draw it in the new view. And I'm not sure if UITabBar would somehow prevent adding the subview or prevent the subview from being on top. But that's where I'd start.
Add the following code in AppDelegate.m didFinishLaunchingWithOptions: method
if ([[[UIDevice currentDevice] systemVersion] floatValue]>=7.0)
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
This worked for me
UIImage* tabBarBackground = [UIImage new];
if(!OSVersionIsAtLeastiOS7())
{
tabBarBackground = [UIImage imageNamed:#"whitebg"];
}
[[UITabBar appearance] setShadowImage:tabBarBackground];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[_tabBarController.tabBar setBackgroundImage:[UIImage imageNamed:#"tabtarsprnt"]]; //your custom image
[self.tabBarController.tabBar setClipsToBounds:YES];
this code also solved the my issue
In my case I also needed to set a different shadow, in the end the only thing that worked while also setting a custom shadow was to add a single-point high UIView 1 point above the tab bar:
UIView *whiteLine = [[UIView alloc] initWithFrame:CGRectMake(0.0, -1.0, self.tabBar.frame.size.width, 1.0)];
whiteLine.backgroundColor = [UIColor whiteColor];
[self.tabBar addSubview:whiteLine];
Try this,
** Objective-C **
//Remove shadow image by assigning nil value.
[[UITabBar appearance] setShadowImage: nil];
// or
// Assing UIImage instance without image reference
[[UITabBar appearance] setShadowImage: [[UIImage alloc] init]];
** Swift **
//Remove shadow image by assigning nil value.
UITabBar.appearance().shadowImage = nil
// or
// Assing UIImage instance without image reference
UITabBar.appearance().shadowImage = UIImage()
Here is apple document for shadowImage.
#available(iOS 6.0, *)
open var shadowImage: UIImage?
Default is nil. When non-nil, a custom shadow image to show instead of
the default shadow image. For a custom shadow to be shown, a custom
background image must also be set with -setBackgroundImage: (if the
default background image is used, the default shadow image will be
used).
now you can use it, with this line:
self.tabBarController.tabBar.barStyle = UIBarStyleBlack;

How to change navigation bar color in iOS 7 or 6?

I want to change the color of the navigation bar color, but I'm not sure whether or not I should change the tint or the background. I know iOS 7 is going for a more flat design (even recommending removing gradients), but I am having trouble deciphering the two. Even if I set a background color, it doesn't do anything.
In this image, the background is set to green, but the bar is still blue:
The behavior of tintColor for bars has changed on iOS 7.0. It no longer affects the bar's background and behaves as described for the tintColor property added to UIView.
To tint the bar's background, please use -barTintColor.
navController.navigationBar.barTintColor = [UIColor navigationColor];
If you want to have a solid color for your navigation bar in iOS 6 similar to iOS 7 use this:
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundColor:[UIColor greenColor]];
in iOS 7 use the barTintColor like this:
navigationController.navigationBar.barTintColor = [UIColor greenColor];
or
[[UINavigationBar appearance] setBarTintColor:[UIColor greenColor]];
// In ios 7 :-
[self.navigationController.navigationBar setBarTintColor:[UIColor yellowColor]];
// In ios 6 :-
[self.navigationController.navigationBar setTintColor:[UIColor yellowColor]];
The background color property is ignored on a UINavigationBar, so if you want to adjust the look and feel you either have to use the tintColor or call some of the other methods listed under "Customizing the Bar Appearance" of the UINavigationBar class reference (like setBackgroundImage:forBarMetrics:).
Be aware that the tintColor property works differently in iOS 7, so if you want a consistent look between iOS 7 and prior version using a background image might be your best bet. It's also worth mentioning that you can't configure the background image in the Storyboard, you'll have to create an IBOutlet to your UINavigationBar and change it in viewDidLoad or some other appropriate place.
One more thing, if you want to change the navigation bg color in UIPopover you need to set barStyle to UIBarStyleBlack
if([UINavigationBar instancesRespondToSelector:#selector(barTintColor)]){ //iOS7
navigationController.navigationBar.barStyle = UIBarStyleBlack;
navigationController.navigationBar.barTintColor = [UIColor redColor];
}
Here is how to set it correctly for both iOS 6 and 7.
+ (void)fixNavBarColor:(UINavigationBar*)bar {
if (iosVersion >= 7) {
bar.barTintColor = [UIColor redColor];
bar.translucent = NO;
}else {
bar.tintColor = [UIColor redColor];
bar.opaque = YES;
}
}
The complete code with version checking.
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
// do stuff for iOS 7 and newer
[self.navigationController.navigationBar setBarTintColor:[UIColor yellowColor]];
}
else {
// do stuff for older versions than iOS 7
[self.navigationController.navigationBar setTintColor:[UIColor yellowColor]];
}
You can check iOS Version and simply set the tint color of Navigation bar.
if (SYSTEM_VERSION_LESS_THAN(#"7.0")) {
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.9529 green:0.4392 blue:0.3333 alpha:1.0];
}else{
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.9529 green:0.4392 blue:0.3333 alpha:1.0];
self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
Based on posted answered, this worked for me:
/* check for iOS 6 or 7 */
if ([[self navigationController].navigationBar respondsToSelector:#selector(setBarTintColor:)]) {
[[self navigationController].navigationBar setBarTintColor:[UIColor whiteColor]];
} else {
/* Set background and foreground */
[[self navigationController].navigationBar setTintColor:[UIColor whiteColor]];
[self navigationController].navigationBar.titleTextAttributes = [[NSDictionary alloc] initWithObjectsAndKeys:[UIColor blackColor],UITextAttributeTextColor,nil];
}
you can add bellow code in appdelegate.m .if your app is navigation based
// for background color
[nav.navigationBar setBarTintColor:[UIColor blueColor]];
// for change navigation title and button color
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],
NSForegroundColorAttributeName,
[UIFont fontWithName:#"FontNAme" size:20],
NSFontAttributeName, nil]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
Insert the below code in didFinishLaunchingWithOptions() in AppDelegate.m
[[UINavigationBar appearance] setBarTintColor:[UIColor
colorWithRed:26.0/255.0 green:184.0/255.0 blue:110.0/255.0 alpha:1.0]];
I'm using following code (in C#) to change the color of the NavigationBar:
NavigationController.NavigationBar.SetBackgroundImage (new UIImage (), UIBarMetrics.Default);
NavigationController.NavigationBar.SetBackgroundImage (new UIImage (), UIBarMetrics.LandscapePhone);
NavigationController.NavigationBar.BackgroundColor = UIColor.Green;
The trick is that you need to get rid of the default background image and then the color will appear.
If you want to change a color of a navigation bar, use barTintColor property of it. In addition, if you set any color to tintColor of it, that affects to the navigation bar's item like a button.
FYI, you want to keep iOS 6 style bar, make a background image looks like previous style and set it.
For more detail, you can get more information from the following link:
https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/AppearanceCustomization.html
In iOS7, if your navigation controller is contained in tab bar, splitview or some other container, then for globally changing navigationbar appearance use following method ::
[[UINavigationBar appearanceWhenContainedIn:[UITabBarController class],nil] setBarTintColor:[UIColor blueColor]];
Try the code below in the - (void)viewDidLoad of your ViewController.m
[[[self navigationController] navigationBar] setTintColor:[UIColor yellowColor]];
this did work for me in iOS 6.. Try it..
I'm not sure about changing the tint vs the background color but this is how you change the tint color of the Navigation Bar:
Try this code..
[navigationController.navigationBar setTintColor:[UIColor redColor]; //Red as an example.

Resources