How to access UITabBarBackgroundView - ios

I have been trying to make transparent tabBar background, but something, called UITabBarBackgroundView, is present and has white background.
How can i access it?

I don't think there is a direct way of doing this. You will have to create an illusion of transparency here. One way to do this is to set an image in tab bar. You can add following category on UITabBarController and call it
- (void) setBackgroundImage:(UIImage *)image
{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)];
imageView.backgroundColor = [UIColor colorWithPatternImage:image];
[self.view addSubview:imageView];
[self.view sendSubviewToBack:imageView];
[self.view setOpaque:NO];
[self.view setBackgroundColor:[UIColor clearColor]];
}
Another way (image way only :)):
UIImage *tabBarBackground = [UIImage imageNamed:#"tabBarBackground.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance] setSelectedImageTintColor:[UIColor colorWithRed:127.0/255.0 green:186.0/255.0 blue:235.0/255.0 alpha:1.0]];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:#"tabBarItemSelected.png"]];

Related

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

Unable to remove shadow from the Navigation Bar

I am trying to remove shadow from the navigationbar but not get success (iOS7).
Used the code below,
Method 1
[self.navigationController.navigationBar setBackgroundImage:image
forBarPosition:UIBarPositionAny
barMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
Method 2
for (UIView *view in self.navigationController.navigationBar.subviews) {
for (UIView *view2 in view.subviews) {
if ([view2 isKindOfClass:[UIImageView class]]) {
[view2 removeFromSuperview];
}
}
}
Method 3
[self.layer setMasksToBounds:YES];
Method 4
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
Method 5
[self.navigationController.navigationBar setBackgroundImage:image
forBarPosition:UIBarPositionAny
barMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[[UIImage imageNamed:#"transparentpx.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(1, 1, 1, 1)]];
None of them worked for me.
Could any one suggest new method..
Using an empty image hasn't worked for me.
I had to use a 1x1 pixel transparent image as the shadow image in order for it to appear invisible.
[self.navigationBar setShadowImage:[[UIImage imageNamed:#"navbar-shadow"] resizableImageWithCapInsets:UIEdgeInsetsMake(1, 1, 1, 1)]];
Have you tried this?
self.navigationController.navigationBar.layer.opacity = 0;
self.navigationController.navigationBar.layer.borderWidth = 0;
self.navigationController.navigationBar.layer.borderColor = [[UIColor clearColor] CGColor];

how to remove line in UITabBar?

Help remove the line in tab bar!
`[[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];` - NOT WORK
CODE:
[[UITabBar appearance] setBarTintColor:[UIColor colorWithRed:54.0f/255.0f green:62.0f/255.0f blue:69.0f/255.0f alpha:1.0f]];
[[UITabBar appearance] setTintColor:[UIColor whiteColor]];
[[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];
[[self.tabBar.items objectAtIndex:0] setFinishedSelectedImage:[UIImage imageNamed:#"barMap.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"barMapNo.png"]];
[[self.tabBar.items objectAtIndex:2] setFinishedSelectedImage:[UIImage imageNamed:#"barNews.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"barNewsNo.png"]];
[[self.tabBar.items objectAtIndex:1] setFinishedSelectedImage:[UIImage imageNamed:#"barNew.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"barNewNo.png"]];
If you're trying to remove the shadowImage then just do the same thing you're doing, but assign it to shadowImage instead of backgroundImage.
It looks likes you're setting an image to a tab bar item (with default frame) when the image is larger than the button's frame. You need to replace the entire button!
UIImage *image = [UIImage imageNamed:#"image"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, image.size.width, image.size.height);
[button setImage:image forState:UIControlStateNormal];
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:button];
[tabBar setItems:#[ barButton, /* etc */ ]];
Try this,
//Remove shadow image by assigning nil value.
[[UITabBar appearance] setShadowImage: nil];
// or
// Assing UIImage instance without image reference
[[UITabBar appearance] setShadowImage: [[UIImage alloc] init]];
Here is apple guideline for shadow image.
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).

How to apply a background image to navigation bar

I want to insert an image to the navigation bar.
My code is
UINavigationBar *navBar = self.navigationController.navigationBar;
UIImage *image = [UIImage imageNamed:#"bodyBg.png"];
[navBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
I have attached the screenshot of the current output. Is this because of the large image size?
But my desired output is
First, make your navigation bar image size 1024x44 pixels nad for retina display 2048x88 pixels.
If you have the same image for UINavigationBar on every view controller, put this to AppDelegate in method didFinishLaunchingWithOptions:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"nav-background.png"] forBarMetrics:UIBarMetricsDefault];
// This will remove shadow in iOS6
if ([[UINavigationBar class] instancesRespondToSelector:#selector(shadowImage)]) {
[[UINavigationBar appearance] setShadowImage:[[[UIImage alloc] init] autorelease]];
}
And also I see you need custom back button, also put this in AppDelegate:
UIImage *backButtonNormal = [UIImage imageNamed:#"nav-back.png"];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonNormal forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
you can set the color of navigation bar same as your image use below code and you can put image name which you want to show in navigation bar
self.navigationController.navigationBar.tintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"bodyBg.png"]];
try it out with this code..
if ([navBar respondsToSelector:#selector(setBackgroundImage:forBarMetrics:)])
{
[navBar setBackgroundImage:[UIImage imageNamed:#"Nav.png"] forBarMetrics:UIBarMetricsDefault];
}
else
{
UIImageView *imageView = (UIImageView *)[navBar viewWithTag:1];//any tag
if (imageView == nil)
{
imageView = [[UIImageView alloc] initWithImage:
[UIImage imageNamed:#"Nav.png"]];
[navBar insertSubview:imageView atIndex:0];
[imageView release];
}
}
see my full answer from this link setting-title-for-uinavigation-bar-in-iphone
self.navigationController.navigationBar.tintColor = [UIColor clearColor];
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"navBar"] forBarMetrics:UIBarMetricsDefault];
I hope , it will work for u
Use UINavigationBar's setBackgroundImage: forBarMetrics: method :
[self.navigationController.navigationBar setBackgroundImage:yourImageHere forBarMetrics:UIBarMetricsDefault];
your UIImage should be of appropriate height and width. For example iphone 4 retina size would be 640*88 for portrait.
EDIT : Point here is if UIImage height is bigger say 150 pixel height it will display that much height and our UINavigationBar height is 44 pixel.
check this link for add background image in navigationbar and first you your navigationbar
image size set as navigationbar.
check this link here
i hope this code useful for you.
[myNavbar setBackgroundImage:[UIImage imageNamed: #"UINavigationBarBackground.png"]
forBarMetrics:UIBarMetricsDefault];
and also this link
Try this code it works for me:
UIView* navigationBGView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
UIImage * targetImage = [UIImage imageNamed:#"Header_top.png"];
UIGraphicsBeginImageContextWithOptions(navigationBGView.frame.size, NO, 0.f);
[targetImage drawInRect:CGRectMake(0.f, 0.f, navigationBGView.frame.size.width, navigationBGView.frame.size.height)];
UIImage * resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
navigationBGView.backgroundColor = [UIColor colorWithPatternImage:resultImage];
[self.navigationController.navigationBar addSubview:navigationBGView];
[self.navigationController.navigationBar setTintColor:[UIColor clearColor]];

Custom transparent UITabBar

I am trying to create an app in which the tab bar transparent (or which looks transparent). For this i'm using part of an image in the view. And set the remaining part as background for tab bar. The problem is the tab bar appears with a darker shade. I'm out of ideas now.
Below is the screen shot
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tabbar_bg.png"]];
self.tabBar.backgroundColor=[UIColor whiteColor];
[self.tabBar insertSubview:imgView atIndex:1];
// [self.tabBar setSelectionIndicatorImage:[UIImage imageNamed:#"transp.png"]];
// [self.tabBar setSelectedImageTintColor:[UIColor clearColor]];
[[UITabBar appearance] setTintColor:[UIColor clearColor]];
[[UITabBar appearance] setSelectedImageTintColor:[UIColor clearColor]];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:#"transp.png"]];
The above is the code that i've tried out in the viewDidLoad of my custom UITabBarController class. "tabbar_bg.png" is the image used as background for the tab bar and 'transp.png' is a transparent image used as the selectionIndicator image.
Thanks for the help.
Try
[self.tabBar setBackgroundImage:[UIImage new]];
This trick also works for UINavigationBar.
Have you tried creating a subclass of it?
#implementation TabBarInvisible
-(id)init
{
self = [super init];
if (self)
{
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
self.backgroundImage = nil;
}
return self;
}
-(void)drawRect:(CGRect)rect
{
}
#end

Resources