Under iOs7, and not earlier versions, I've a line who pass through my Tab Bar (shown with green arrow on example picture from the link below).
I don't know where the problem come from. Any idea how to correct it ?
Thank you very much.
I think you have to check the height of UITabBar in iOS 7. It is possible Apple has decreased the height of UITabBar, as per height of UITabBar you have to redesign your image for accurate result.
If you're referring to the couple of pixel shadow on top of the bar, it's easy to remove. All you have to do is enable clipsToBounds on your tab bar, like so:
[self.tabBarController.tabBar setClipsToBounds:YES];
Add these two line after you create the TabBar
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
[[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];
UIImage* tabBarBackground = [UIImage imageNamed:@"transparentImage.png"];
[[UITabBar appearance] setShadowImage:tabBarBackground];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
/////transparentImage.png - empty 1x1px image //// It's resolve my problem
use this [[UITabBar appearance] setShadowImage:[UIImage imageNamed:@"transparentImage.png"]];
transparentImage.png can be image with 0 alpha size 1x1 pixel
In case you are struggling with a custom UITabBarItem taller than the UITabBar height, a solution that let you preserve your default UITabBar shadowImage and backgroundImage (with the blur effect) is achieved by using CALayer.
I am using this code in my UITabBarController subclass:
- (id) init
{
if ((self = [super init]))
{
self.delegate = self;
CALayer * superLayer = self.tabBar.layer;
CALayer * layer = [CALayer layer];
layer.bounds = CGRectMake (0.0f, 0.0f, 62.0f, 56.0f);
layer.contents = (id) [UIImage imageNamed: @"custom-tabbaritem"].CGImage;
layer.anchorPoint = CGPointMake (0.5f, 1.0f);
layer.position = CGPointMake (superLayer.bounds.size.width / 2.0f, superLayer.bounds.size.height);
layer.zPosition = 1.0f;
[self.tabBar.layer addSublayer: layer];
}
return self;
}
Note that you can also use layer.frame = CGRectMake (...)
in place of bounds
, anchorPoint
and position
. I am using these ones to better deal with images with various heights by anchoring the sublayer to the bottom of the UITabBar
.
By implementing a UITabBarControllerDelegate method such as tabBarController:shouldSelectViewController:
it is possible to make this UITabBarItem
do custom actions, for example presenting a modal view controller.
In this case I used a plain UIViewController
as the view controller for the custom UITabBarItem
(the other ones are all subclasses):
- (BOOL) tabBarController: (UITabBarController *) tabBarController
shouldSelectViewController: (UIViewController *) viewController
{
if ([viewController isMemberOfClass: [UIViewController class]])
{
SomeViewController * modal = [SomeViewController new];
[tabBarController presentViewController: modal
animated: YES
completion: nil];
modal = nil;
return NO;
}
return YES;
}
来源:https://stackoverflow.com/questions/18785930/an-unwanted-line-on-tab-bar-controller-under-ios7