iOS 7 tabBar-line, how to remove it?

前端 未结 12 1275
执笔经年
执笔经年 2021-01-31 07:52

Apple has added a tiny line over the tabBar in iOS 7 which is supposed to work as a shadow or fade between the tabBar and the UI

相关标签:
12条回答
  • 2021-01-31 08:35

    In iOS 8 the top border can be removed by setting the tab bar style to black in the inspector.

    0 讨论(0)
  • 2021-01-31 08:35

    Add the following code in AppDelegate.m didFinishLaunchingWithOptions: method

    if ([[[UIDevice currentDevice] systemVersion] floatValue]>=7.0)
     [[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
    
    0 讨论(0)
  • 2021-01-31 08:38

    I'm not seeing anything in the UITabBar API for affecting that separator, but if the separator is within the UITabBar (a UIView subclass), I'd expect you can insert a new one-pixel-high UIView on top of it. You'd have to grab a slice of the image that you want to appear there and draw it in the new view. And I'm not sure if UITabBar would somehow prevent adding the subview or prevent the subview from being on top. But that's where I'd start.

    0 讨论(0)
  • 2021-01-31 08:38

    Try this, ** Objective-C **

    //Remove shadow image by assigning nil value.
    [[UITabBar appearance] setShadowImage: nil];
    
    // or 
    
    // Assing UIImage instance without image reference
    [[UITabBar appearance] setShadowImage: [[UIImage alloc] init]];
    

    ** Swift **

    //Remove shadow image by assigning nil value.
    UITabBar.appearance().shadowImage = nil
    
    // or 
    
    // Assing UIImage instance without image reference
    UITabBar.appearance().shadowImage = UIImage()
    


    Here is apple document for shadowImage.

    @available(iOS 6.0, *)
    open var shadowImage: UIImage?
    

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

    0 讨论(0)
  • 2021-01-31 08:40

    In my case I also needed to set a different shadow, in the end the only thing that worked while also setting a custom shadow was to add a single-point high UIView 1 point above the tab bar:

        UIView *whiteLine = [[UIView alloc] initWithFrame:CGRectMake(0.0, -1.0, self.tabBar.frame.size.width, 1.0)];
        whiteLine.backgroundColor = [UIColor whiteColor];
        [self.tabBar addSubview:whiteLine];
    
    0 讨论(0)
  • 2021-01-31 08:48

    This worked for me

    UIImage* tabBarBackground = [UIImage new];
    if(!OSVersionIsAtLeastiOS7())
    {
        tabBarBackground = [UIImage imageNamed:@"whitebg"];
    }
    [[UITabBar appearance] setShadowImage:tabBarBackground];
    
    [[UITabBar appearance] setBackgroundImage:tabBarBackground];
    
    0 讨论(0)
提交回复
热议问题