43
votes

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.

15
iOS 10.X have some changes so please follow THIS ANSWER.Mitul Marsoniya

15 Answers

40
votes

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

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

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()
16
votes

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

Swift 4

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

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()
}
2
votes

Calling [[UITabBar appearance] setShadowImage:] will customise all UITabBar instances in your app.

If you want to customize just one UITTabBar, you can do this:

[self.tabBarController.navigationController.navigationBar setShadowImage:[UIImage new]];
2
votes

Here's another easy to implement answer:

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

Worked for me.

2
votes

Just be setting image it will not remove the shadow line you have to set it's borderWidth to 0. here is the code

[[UITabBar appearance] setShadowImage:[UIImage new]];

[UITabBar appearance].layer.borderWidth = 0.0f;

[UITabBar appearance].clipsToBounds = true;

1
votes

Place this in your AppDelegate under didFinishLaunchingWithOptions:

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

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

1
votes

I have achieved the same look by following method.
1. Set the background bar tint colour to same as the main parent view background colour.
2.

this.TabBar.BarStyle = UIBarStyle.BlackOpaque;

I used it in Xamarin, Please verify the Swift syntax.

1
votes

if you need to remove the shadow line on iOS 13 from a tab bar that has a custom font, then you have to apply it this way:

if #available(iOS 13.0, *) {
   let appearance = UITabBarAppearance()
   appearance.stackedLayoutAppearance.normal.titleTextAttributes = ...
   appearance.stackedLayoutAppearance.selected.titleTextAttributes = ...
   appearance.shadowColor = .clear
   tabBar.standardAppearance = appearance
 }

0
votes

In your view controller or view controllers or BasicViewController that most of the viewcontrollers inherit in the viewDidLoad just put these 2 lines:

[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"tab_bar_background"]];
[[UITabBar appearance] setShadowImage:[UIImage imageNamed:@"transparent_shadow"]];

Be sure [email protected] is an image 1x1 or 2x2 transparent and the [email protected] is an image 640x100 as the bottom bar is 50px in height.

Works on iOS 9.3

0
votes

Try this on viewDidload.

override func viewDidLoad() {
        super.viewDidLoad()

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

It work for me

-1
votes

In iOS 7 - this works:

[self.actionToolbar setShadowImage:[[UIImage alloc] init] forToolbarPosition:UIBarPositionAny];
[self.actionToolbar setBackgroundImage:[[UIImage alloc] init] forToolbarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];

Hope that helps someone.