iOS 7 complete UINavigationBar transparency - ios

I'm trying to make this transparency look in a ViewControllers Navigation bar:
WANTED:
Till now i got only this done. The bar is not losing its color:
Used code:
self.navigationController.navigationBar.barTintColor = [UIColor clearColor];
self.navigationController.navigationBar.translucent = YES;
Any idea how to fix this?

Try this:
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [UIImage new];
self.navigationController.navigationBar.translucent = YES;
And in Swift
self.navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
self.navigationController?.navigationBar.shadowImage = UIImage()
self.navigationController?.navigationBar.translucent = true

Please try these codes:
//set the nav bar complete transparent
[self.navigationController.navigationBar setBackgroundImage:[self imageWithColor:[UIColor clearColor]] forBarMetrics:UIBarMetricsDefault];
//remove the bottom show from nav bar
self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
- (UIImage *)imageWithColor:(UIColor *)color {
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}

Related

How to hide 1px UINavigationBar hairline from the middle of the UINavigation Bar

I have added UINavigation bar with a background image.
But unfortunately an unwanted 1px hairline is displaying at the middle of the UINavigation Bar.
I want to hide that line, but it's not working. I have added following code.
self.navigationController.navigationBar.translucent = NO;
[self.navigationController.navigationBar setShadowImage:nil];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"navBarImg.png"] forBarMetrics:UIBarMetricsDefault];
if you do not need to set the navigationbar become transparent, you can use the following code
[self.navigationController.navigationBar setBackgroundImage:[self imageFromColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:1]] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
and adding the following method to generate an uiimage.
- (UIImage *)imageFromColor:(UIColor *)color {
CGRect rect = CGRectMake(0, 0, 1, 1);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}

Nav bar is translucent, but I would like transparent

I have followed the top guides on how to make my top bar transparent, but the best I can get is translucent. I am also trying to get the buttons white, not default blue. What am I missing?
#implementation FindAssetLocationMapViewController
- (void) viewWillAppear:(BOOL)animated {
self.edgesForExtendedLayout = UIRectEdgeAll;
self.extendedLayoutIncludesOpaqueBars = true;
[self.navigationController.navigationBar setTranslucent:YES];
self.navigationController.navigationBar.shadowImage = [UIImage new];
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
self.view.backgroundColor = [UIColor redColor];
}
Images are below. Should I take screenshots of the FindAssetLocationMapViewController attributes as well? Just to clarify, the nav controller and nav bar attributes do not have a class associated with them.
Try this code in your app delegate, then remove the code you have:
+ (UIImage *)imageWithColor:(UIColor *)color
{
CGRect rect = CGRectMake(0, 0, 1, 1);
// create a 1 by 1 pixel context
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0);
[color setFill];
UIRectFill(rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
Place this inside application:didFinishLaunchingWithOptions:
//create background images for the navigation bar
UIImage *clear = [AppDelegate imageWithColor:[UIColor clearColor]];
//customize the appearance of UINavigationBar
[[UINavigationBar appearance] setBackgroundImage:clear forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundImage:clear forBarMetrics:UIBarMetricsCompact];
[[UINavigationBar appearance] setTranslucent:NO];
[[UINavigationBar appearance] setShadowImage:[UIImage new]];

Completely transparent UITabBar in iOS 8

I'm trying to make my tabBar transparent, I've searched but all I found was articles resulting in partly and not fully transparent tabBars and some were for IOS 5, etc.
I would like to accomplish this as seen in Sketch 3:
What's the easiest way to accomplish this?
I thought of doing this:
// Make the tabBar transparent
self.tabBarController.tabBar.backgroundColor = [UIColor clearColor];
self.tabBarController.tabBar.translucent = YES;
but that result wasn't exactly perfect:
Really appreciate help!:)
Sincerely,
Erik
Update
// Make the tabBar transparent
[[UITabBar appearance] setBarTintColor:[UIColor clearColor]];
self.tabBarController.tabBar.translucent = YES;
Have you tried the barTintColor?
[[UITabBar appearance] setBarTintColor:[UIColor clearColor]];
[[UITabBar appearance] setBackgroundImage:[UIImage new]];
That should do the trick.
Swift 3.0
... call this code in the AppDelegate's didFinishLaunchingWithOptions
let tabBar = UITabBar.appearance()
tabBar.barTintColor = UIColor.clear
tabBar.backgroundImage = UIImage()
tabBar.shadowImage = UIImage()
The result will be a transparent background for every UITabBar.
You need to subclass the UITabBarController and in the viewdidload: you should put this code:
CGRect rect = CGRectMake(0, 0, 1, 1);
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 1.0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
CGContextFillRect(context, rect);
UIImage *transparentImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[self.tabBar setBackgroundImage:transparentImage];
[self.tabBar setShadowImage:transparentImage];
// self.tabBar.alpha = 0.0;
I solved the problem using the following code:
let tabBarController = UITabBarController()
...
tabBarController.tabBar.backgroundImage = UIImage()
tabBarController.tabBar.barTintColor = .clear
tabBarController.tabBar.isTranslucent = true
tabBarController.extendedLayoutIncludesOpaqueBars = true
tabBarController.edgesForExtendedLayout = .all

iOS 7 navigation bar height

Is it possible to change navigation bar height in iOS 7?
why I need navigation bar:
to have a transparent navigation bar with the right positions of others elements on my view without any problems;
I don't want to create a fake "navigation bar" - in this case I'll need to set up all positions myself.
//make real nav bar invisible
self.navigationBar.barTintColor = [UIColor clearColor];
UIImage* transparentImage = [UIImage emptyImageWithSize:CGSizeMake(self.navigationBar.frame.size.width, 1) andBackgroundColor:[UIColor clearColor]];
[self.navigationBar setBackgroundImage:transparentImage forBarMetrics:UIBarMetricsDefault];
self.navigationBar.shadowImage = transparentImage;
and then
UINavigationBar* fakeNavigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.navigationBar.frame.size.width, neededHeight)];
fakeNavigationBar.barTintColor = [UIColor whiteColor];
[self.navigationBar insertSubview:fakeNavigationBar atIndex:0];
where
+ (UIImage*)emptyImageWithSize:(CGSize)size andBackgroundColor:(UIColor*)color
{
CGRect frameRect = CGRectMake(0, 0, size.width, size.height);
UIGraphicsBeginImageContext(size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(ctx, color.CGColor); //image frame color
CGContextFillRect(ctx, frameRect);
UIImage* resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultImage;
}
In your app delegate
UINavigationController *NavController=[[UINavigationController alloc]initWithRootViewController:HomeViewController];
[NavController.navigationBar setBounds:CGRectMake(10, 30, 40, 10)];

Unable to make Navigation Bar totally transparent in iOS6

I was using the following code to make my Navigation Bar transparent in iOS5:
const float colorMask[6] = {222, 255, 222, 255, 222, 255};
UIImage *img = [[UIImage alloc] init];
UIImage *maskedImage = [UIImage imageWithCGImage: CGImageCreateWithMaskingColors(img.CGImage, colorMask)];
[self.navigationController.navigationBar setBackgroundImage:maskedImage forBarMetrics:UIBarMetricsDefault];
Upgraded to iOS6 and the Navigation Bar is still transparent but now has a thin black line underneath it. How can I make the Navigation Bar totally transparent?
I have also tried all of the following:
self.navigationController.navigationBar.translucent = YES;
self.navigationController.navigationBar.opaque = YES;
self.navigationController.navigationBar.tintColor = [UIColor clearColor];
self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
[[UINavigationBar appearance] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
Thanks in advance.
Solved. iOS6 has added a drop shadow to the Navigation Bar. So the masking code that I was using with iOS5 still works fine - I just need to add
if ([self.navigationController.navigationBar respondsToSelector:#selector(shadowImage)])
{
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
}
to get rid of the drop shadow.
self.navigationController.navigationBar.translucent = YES; // Setting this slides the view up, underneath the nav bar (otherwise it'll appear black)
const float colorMask[6] = {222, 255, 222, 255, 222, 255};
UIImage *img = [[UIImage alloc] init];
UIImage *maskedImage = [UIImage imageWithCGImage: CGImageCreateWithMaskingColors(img.CGImage, colorMask)];
[self.navigationController.navigationBar setBackgroundImage:maskedImage forBarMetrics:UIBarMetricsDefault];
//remove shadow
[[UINavigationBar appearance] setShadowImage: [[UIImage alloc] init]];
if ([self.navigationController.navigationBar respondsToSelector:#selector(shadowImage)])
{
[self.navigationController.navigationBar setShadowImage:[[[UIImage alloc] init] autorelease]];
// autorelease is necessary, or else [[UIImage alloc] init]'s retainCount is 2.
}

Resources