how to remove line in UITabBar? - ios

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).

Related

How to set image on UITabbaritem?

I am working on UITabbarview controller, I set an image with the following code, but it is not visible the first time I open a view.
UIImage *prfimage = [UIImage imageNamed:#"profile_o.png"]; UITabBarItem *tbP = [[UITabBarItem alloc] initWithTitle:#"" image:prfimage tag:YES];
[self setTabBarItem:tbP];
[[UITabBar appearance] setTintColor:[UIColor colorWithRed:247/255.0f green:148/255.0f blue:29/255.0f alpha:2.0f]];
self.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
self.title = nil;
You should use this peace of code to set UIImage in your ViewController
[[[[self.tabBarController tabBar] items] objectAtIndex:0] setImage:[[UIImage imageNamed:#"yourImage"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]] ;//objectAtIndex:0 mean your first TabBar item You can do it for multiple.
It will help.Thanks

How to access UITabBarBackgroundView

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

Change item color in UITabBar iOS

My app has a Tab Bar like the follow:
The Tab Bar must be green and as you can see the icon of the item in Tab Bar are a little hard to see. How I can change the color of the icon in this Tab Bar? I've to use the standard Tab Bar.
Thank you
try this
[[self tabBar] setSelectedImageTintColor:[UIColor greenColor]];
or this
[UITabBarItem.appearance setTitleTextAttributes:#{
UITextAttributeTextColor : [UIColor greenColor] } forState:UIControlStateNormal];
[UITabBarItem.appearance setTitleTextAttributes:#{
UITextAttributeTextColor : [UIColor purpleColor] } forState:UIControlStateSelected];
Or this
[[self tabBar] setTintColor:[UIColor redColor]];
or this
[UITabBarItem.appearance setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor greenColor]} forState:UIControlStateNormal];
[UITabBarItem.appearance setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor purpleColor]} forState:UIControlStateSelected];
Instead using of icon you can use icon image by using the following code
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
tabBarItem1.selectedImage = [[UIImage imageNamed:#"selectedImage.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabBarItem1.image = [[UIImage imageNamed:#"unselectedImage.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
tabBarItem1.imageInsets= UIEdgeInsetsMake(6, 0, -6, 0);
Try this
[[UITabBar appearance] setTintColor:[UIColor redColor]];
[[UITabBar appearance] setBarTintColor:[UIColor yellowColor]];
// set tabbar background image
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:#"tabbar_bg"]];
// remove shadow image of tabbar
[[UITabBar appearance] setShadowImage:[[UIImage alloc]init]];
I would suggest, to change background of UITabbar to some darker colours, instead of green. Just leave the default gray color(Apple masks to gray) for unselected tab. Use below snipped to set selected tab mask color.
[[UITabBar appearance] setTintColor:[UIColor redColor]];
This will avoid confusion to end users whether a tab is selected or in unselected state.

Change tintColor of unselected UITabBarController item title and background image

How can I change the tintColor of an unselected UITabBarItem title and background image iOS 8?
The default color for an unselected state is a light gray color, but it does not show on my darkish shade UITabBar background
I'd like my unselected state to have a color of [UIColor blackColor]
Inside my app delegate didfinishlaunchingwithoptions: I have
UIImage *deselectedE = [[UIImage imageNamed:#"mincraft_axe_green_32.png"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
UIImage *selectedE = [[UIImage imageNamed:#"mincraft_axe_green_32.png"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
e.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Profile" image:deselectedE selectedImage:selectedE];
[[UITabBar appearance] setTintColor:[UIColor blackColor]];
Figured it out!
Use this to change the color of the text:
[[UITabBarItem appearance] setTitleTextAttributes:#{ NSForegroundColorAttributeName : [UIColor greenColor] }
forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:#{ NSForegroundColorAttributeName : [UIColor blackColor] }
forState:UIControlStateSelected];
And make sure that image rendering mode is set to ORIGINAL for the images
UIImage *deselectedImage = [[UIImage imageNamed:#"deselectedImage"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *selectedImage = [[UIImage imageNamed:#"selectedImage"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
In your AppDelegate.m inside of application didFinishLaunchingWithOptions: use the following code:
//unselected icon tint color
[[UIView appearanceWhenContainedIn:[UITabBar class], nil] setTintColor:[UIColor redColor]];
//selected tint color
[[UITabBar appearance] setTintColor:[UIColor greenColor]];
//text tint color
[[UITabBarItem appearance] setTitleTextAttributes:#{ NSForegroundColorAttributeName : [UIColor whiteColor] }
forState:UIControlStateNormal];
//background tint color
[[UITabBar appearance] setBarTintColor:[UIColor blueColor]];
You can also render the image as original from the attributes inspector for the asset file without writing any code
You can also set it up directly in Storyboard... Check my answer here:
How to set UITabBarItem's unselected tint, ***including system items*** (iOS7)
If you're using Storyboard you can also set both Image for Bar Item and Selected Image for Selected Bar Item to get unaltered image in tabBar.
Alternatively in Assets catalog, you can select Render As: Original Image in the attributes of your image (View > Utilities > Show Attributes Inspector or shortcut ⌥⌘4 (Option + Command + 4))

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

Resources