iOS 7 navigation bar height - ios

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)];

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 complete UINavigationBar transparency

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;
}

How to change UINavigationController background color?

I'm able to change the backgroung image of UINavigationController by overriding drawRect: method:
#implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
UIImage *img = [UIImage imageNamed: #"navController.png"];
[img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
self.tintColor = [UIColor blueColor];
}
#end
the background is what I intended to be and the tintColor as well, but when trying to set a color that isn't existing in UIColor class it fails and shows strange color:
#implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
UIImage *img = [UIImage imageNamed: #"navController.png"];
[img drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
self.tintColor = [UIColor colorWithRed:(26/255) green:(103/255) blue:(159/255) alpha:1];
}
#end
How can I force UINavigationBar to show the color I want?
Note: I'm only having a problem with navigation controller buttons color since the background itself is set to image.
You need to do this:
self.tintColor = [UIColor colorWithRed:(26.0f/255.0f) green:(103.0f/255.0f) blue:(159.0f/255.0f) alpha:1.0f];
Otherwise you're doing integer arithmetic and you'll end up with 0 for all of them probably. Use floating point arithmetic and you get the values you desire.
This Works for me
self.navigationController.navigationBar.backgroundColor= [UIColor colorWithRed:57.0/255.0 green:158.0/255 blue:209.0/255 alpha:1.0];
You can also use:
navigationController.view.backgroundColor = .yourColor

Resources