An unwanted line on Tab bar controller under ios7

偶尔善良 提交于 2019-11-29 08:12:31

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];
gaurish.salunke

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;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!