Transparent Navigation Bar & Tabbar in iOS - ios

I want to have a navigation bar and tabbar transparent to view background (reference image ==> https://www.dropbox.com/s/3vn8ef0p5lv1cw7/Required.png?dl=0). I am already setting background to view. But, I couldn't have Navigation Controller & Tabbar Controller transparent (reference image ==> https://www.dropbox.com/s/vfewqpwve78l4dq/Current.png?dl=0).
This is what I have tried before :
1. Setting background color of Navigation Bar and Tabbar to null/clear color.
2. BarTintColor works for Navigation Bar but it only allows me to set color, cannot have clearcolor (makes it black when I tried)
3. Translucent property !
Please help. Thanks in advance.

try to set transparent background images for navigation bar and tab bar. This will definitely solve your issue.
UIImage *image = [UIImage imageNamed:#"NavigationBar.png"];
[navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
Updated:
[self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationBar.shadowImage = [UIImage new];
self.navigationBar.translucent = YES;

Related

How to make default tab bar as full transparent

Transperent imageI am working on a tab bar application.I applied the color to the tab bar like this
[[UITabBar appearance] setBarTintColor:[UIColor colorWithRed:137.0/255.0f green:27.0/255.0f blue:2.0/255.0f alpha:1.0f]];
My requirement is to display the tab bar transparent like below image
After applying the below code.tab bar is not displaying transparent. but it is displaying with black color background
self.tabBarController.tabBar.backgroundColor = [UIColor clearColor];
self.tabBarController.tabBar.translucent = YES;
Give suggestions for making the default tab bar as transperent
black color background image
You can create an empty image and pass it as a backgroundImage:
[[UITabBar appearance] setBackgroundImage:[UIImage new]];
You can use a similar approach for shadows and tint, but pay attention that a tint color is something very particular that has to deal with you whole UI.

Can't set my navigation bar background image

I want to change my table view navigation bar background image to some png, i created the nav bar png with the exact sizes of a default nav bar (I checked in interface builder).
This is my code (in my table view controller class, viewDidLoad method):
UINavigationBar *navBar = self.navigationController.navigationBar;
UIImage *image = [UIImage imageNamed:#"nav.png"];
[navBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
Shouldn't this work..?
this is my table view settings in the interface builder if this help:
the top one is what i suppose to get and the bottom one is what im getting:
thanks!
UIImageView *backImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"nav.png"]];
[self.navigationController.navigationBar addSubview:backImgView];
Try to add Image in custom view
Why not use the existing nav bar? Don t think you need to create a new one... This code is working for me :
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"nav.png"] forBarMetrics:UIBarMetricsDefault];
Your TableViewController must be "embadded" in a navigation controller a.k.a connected to other ViewControllers as push segue... Then you get your nav bar automatically instead of creating one... I mean you create a nav bar and never add it to the view isnt it?

UINavigationBar appearance setBackgroundImage Hides Status Bar

UIImage *gradientImage46 = [[UIImage imageNamed:#"navbar.png"]resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[UINavigationBar appearance] setBackgroundImage:gradientImage46
forBarMetrics:UIBarMetricsDefault];
I am using this to customize the appearance of my navigation bars in my app. However, this is causing the status bar to be solid black, showing nothing...time, carrier, battery, etc. Is this a bug, or did I implement this incorrect?
I have this running in a tab bar using MainWindow.xib method for interface. The first tab is just a navigation controller with a view controller inside it. Another tab is a Navigation Controller with a TableView Controller inside. If I go from one tab to the table view, and then back, the status bar appears.
The navbar.png is 320 x 44 pixels.
I also have this problem bringing my app from iOS 6 to iOS7, I solved by changing the code in this way:
instead
[UINavigationBar appearance] setBackgroundImage:gradientImage46
forBarMetrics:UIBarMetricsDefault];
i use
-(void) viewWillAppear:(BOOL)animated {
[self.navigationController.navigationBar setBackgroundImage:gradientImage46 forBarMetrics:UIBarMetricsDefault];
}

How do I edit the background color of backBarButtonItem (UINavigationItem) ? iOS 4.3 issue

I am trying to edit the background behind the backBarButtonItem as it insists on remaining white. I have edited the background color of the entire navigation bar but to no avail.
It only seems to affect iOS4 however, seeing as the:
[self.navigationController.navigationBar setBackgroundImage:navBarBackground forBarMetrics:UIBarMetricsDefault];
code works on iOS5. I have also tried to edit the navigation bar using this method also:
#implementation UINavigationBar (UINavigationBarCategory)
-(void)drawRect:(CGRect)rect{
UIImage *img = [UIImage imageNamed:#"bg_actionbar_edit.png"];
[img drawInRect:rect];
}
#end;
however this code results in all of my navigation bars to change, which is something that I do not want. Is there any simple code that I could use to simply change the BG colour of a buttonItem based on the navigation bar?
Set the tint of your navigation bar to change the color of the navigation bar button items:
self.navigationController.navigationBar.tintColor = [UIColor grayColor];

Remove Background Image on UINavigationBar

My app uses a navigation controller with an image on in the navigation bar of the home page. The background image is done by putting
[navigationController.navigationBar setBackgroundImage:navImage forBarMetrics:UIBarMetricsDefault];
[_window addSubview:navigationController.view];
in the app delegate. The nav bar displays this image fine.
Every other view will not have an image in the navigation bar. Therefore, I need to remove this background image when any other view controller is pushed. Does anyone know how this can be done?
There are many answers online about adding or changing a nav bar image, but this question is a little bit different. Thank you in advance.
To remove UINavigationBar background in iOS 5 or later, you should do this:
[navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
Hope it helps
I believe this to be the first actual answer to this for iOS5, the main problem being the "removal" of the background image once you are done. Well, just retain the existing image and put it back when you are done.
#implementation MyViewController {
UIImage *_defaultImage;
}
- (void)viewWillAppear:(BOOL)animated {
_defaultImage = [self.navigationController.navigationBar backgroundImageForBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"bar.png"] forBarMetrics:UIBarMetricsDefault];
}
- (void)viewWillDisappear:(BOOL)animated {
[self.navigationController.navigationBar setBackgroundImage:_defaultImage forBarMetrics:UIBarMetricsDefault];
}
You can set background image with blank image created in runtime.
UIGraphicsBeginImageContextWithOptions(CGSizeMake(36, 36), NO, 0.0);
UIImage *blank = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[[UINavigationBar appearance] setBackgroundImage:blank forBarMetrics:UIBarMetricsDefault];
Creating blank image in runtime:
How to create a blank transparent png in Objective-C?
Nothing here have worked for me. After searching for hours, the only thing that worked was following a source code example provided by Apple.
I placed the following code and it worked and removed the navigation bar image from other view controllers finally!!
// Reset everything about navigation bar. (Other flows' background image used to show up on another view controller)
self.navigationController!.navigationBar.setBackgroundImage(nil, for: .default)
self.navigationController!.navigationBar.setBackgroundImage(nil, for: .compact)
self.navigationController!.navigationBar.barTintColor = nil
self.navigationController!.toolbar.barTintColor = nil
self.navigationController!.toolbar.isTranslucent = true
Hope this helps someone.
Cheers
It looks like the easiest way to do this is to:
1) set the alpha of the navigation bar on the home page to 0.000001
2) put the background image in a UIImageView "behind" the navigation bar (which is now clear)
3) use viewWillAppear / viewWillDisappear to set the navigation bar's opacity to either 1 or 0.00001 when views are pushed / popped.

Resources