iOS UITabBar : Remove top shadow gradient line

38,879

Solution 1

Try setting a 1x1 pixel transparent shadow image for the UITabBar:

[[UITabBar appearance] setShadowImage:[UIImage imageNamed:@"transparentShadow.png"]];

Solution 2

Similary in answer for this question ... if You don't want to mess with any kind of 1x1 transparent image, this work's too:

[[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]]; 
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];

In swift:

UITabBar.appearance().shadowImage = UIImage()
UITabBar.appearance().backgroundImage = UIImage()

Solution 3

Swift

Try this for your custom tab bar. It will hide horizontal shadow line.

self.tabBar.setValue(true, forKey: "_hidesShadow")

Objective C

[self.tabBar setValue:@(YES) forKeyPath:@"_hidesShadow"];

Solution 4

Swift 4

UITabBar.appearance().layer.borderWidth = 0.0
UITabBar.appearance().clipsToBounds = true

Solution 5

This code works both iOS 13 and below

if #available(iOS 13, *) {
    let appearance = self.tabBar.standardAppearance.copy()
    appearance.backgroundImage = UIImage()
    appearance.shadowImage = UIImage()
    appearance.shadowColor = .clear
    self.tabBar.standardAppearance = appearance
} else {
    self.tabBar.backgroundImage = UIImage()
    self.tabBar.shadowImage = UIImage()
}
Share:
38,879

Related videos on Youtube

httpete
Author by

httpete

French engineer, front developer @ Dailymotion

Updated on July 09, 2022

Comments

  • httpete
    httpete almost 2 years

    I implemented a custom UITabBar and I still have this gradient/shadow on top of it. I added

    [self.tabBar setBackgroundImage:[UIImage imageNamed:@"navBarBottom.png"]];

    which is just changing the background but keeping the shadow gradient.

    What am I doing wrong ? Is there anything to specify to get rid of it ?

    What I have :

    top shadow

    What I want :

    without shadow

    Thank you.

    • Mitul Marsoniya
      Mitul Marsoniya over 7 years
      iOS 10.X have some changes so please follow THIS ANSWER.
  • httpete
    httpete over 11 years
    I know how to deal with UITabBarItem shadow and already removed it. My concern is the UITabBar shadow (the big line on the top) that many apps succeeded to remove.
  • httpete
    httpete over 11 years
    It worked, thanks :) (Also for people wondering transparentShadow.png is a 1x1 transparent image)
  • Roger Fernandez Guri
    Roger Fernandez Guri almost 11 years
    Don't forget: [[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];
  • JakubKnejzlik
    JakubKnejzlik almost 11 years
    @Roger: I'm not sure, is it necessary if You just need to remove the shadow?
  • Roger Fernandez Guri
    Roger Fernandez Guri almost 11 years
    Yes. I had to do it to fully remove the shadow otherwise it still displaying it.
  • rordulu
    rordulu over 10 years
    it's "UITabBar" not UIToolBar.
  • Manann Sseth
    Manann Sseth over 10 years
    Thanks mate.. A lots of tries are solved by your code.. Thanks again.
  • Despotovic
    Despotovic over 10 years
    @RogerFernandezGuri, actually it is not still displaying shadow, but what you see is a tab bar background colour. Instead of '[[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];', you could also try setting the background colour...
  • Despotovic
    Despotovic over 10 years
    If you are setting the tab bar background image to custom one, then add: '[[UITabBar appearance] setBackgroundColor:[UIColor clearColor]];'.
  • n13
    n13 almost 9 years
    Important: The value for "setShadowImage" is by default ignored, unless you also set a background image with setBackgroundImage. So you always have to set both! [From Apple docs]
  • n13
    n13 almost 9 years
    Caveat is that this seems undocumented. Better use the - admittedly more tedious - methods above, setting shadow and background images.
  • n13
    n13 almost 9 years
    Upvoted this because you need to set the Background image too. The problem here is that setting the BG to an empty image makes the background transparent, at least if it's a translucent tab bar. Which might not be what you wanted.
  • Pat Niemeyer
    Pat Niemeyer almost 8 years
    You can also add this in Interface Builder in the Identity Inspector pane for the UITabBar under the section "User Defined Runtime Attributes". Hit the + to add a row and enter the _hidesShadow key and value.
  • Luke Rogers
    Luke Rogers over 7 years
    This is accessing a private API, so could be cause for rejection and is likely to break in future versions of iOS.
  • lewis
    lewis almost 7 years
    Null image doesn't work in iOS 11, at least up to and including beta 6.
  • jiexishede
    jiexishede about 6 years
    I use the Swift code. It works for iOS 11 in 04,2018.
  • tobi
    tobi over 5 years
    Just using UITabBar.appearance().clipsToBounds = true has the same effect.
  • SoftDesigner
    SoftDesigner almost 5 years
    Worked on iOS 12. But doesn't work on iOS13 anymore! Have anyone tried? There's a new tabBar.standardAppearance.shadowImage but it doesn't work at all...
  • JAHelia
    JAHelia over 4 years
    if you have custom font on the text of UITabBarItem it will get affected using your method
  • JAHelia
    JAHelia over 4 years
    this solution and all other solutions will affect the uitabbaritem title font, it will not apply the custom font if you have one.