28

On iOS 10 this code doesn't work in order to remove the tabBar shadow line:

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

Somebody knows, what must I do to remove it?

On iOS 9.3 with this two lines the line is removed, but iOS 10 ignores setShadowImage command.

Krunal
  • 77,632
  • 48
  • 245
  • 261
jcamacho
  • 818
  • 2
  • 12
  • 25

15 Answers15

47

removes the topline for @iOS 13.0

let appearance = tabBar.standardAppearance
appearance.shadowImage = nil
appearance.shadowColor = nil
tabBar.standardAppearance = appearance;

removes the topline for iOS 12.0 and earlier

tabBar.shadowImage = UIImage()
tabBar.backgroundImage = UIImage()
sahiljain
  • 2,215
  • 1
  • 29
  • 39
42

Just try to bellow code for iOS 10 :-

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    [[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"fondoTabBar"]];
    [UITabBar appearance].layer.borderWidth = 0.0f;
    [UITabBar appearance].clipsToBounds = true;
    return YES;
}

Swift 3.x

UITabBar.appearance().layer.borderWidth = 0.0
UITabBar.appearance().clipsToBounds = true
Mitul Marsoniya
  • 5,272
  • 4
  • 33
  • 57
  • This code is that I using until iOs 10. This code works on prior iOs 10 device, but on iOs 10 doesn't work. – jcamacho Oct 05 '16 at 06:07
  • Can you please try this demo its work for iOS 10 :- https://www.dropbox.com/sh/g4cpq282b7adyg0/AADk3jBHshvsQ-FNIWwzuOOZa?dl=0 – Mitul Marsoniya Oct 05 '16 at 10:08
  • Thanks for your sample code. This code works on iOs 10 but I need to change tabBar background, when I change background the line is show. This code is the same only I added a background image and you can see that the shadow image is shows on iOs 10, on iOs 9.3 works fine and the line is hidden. https://1drv.ms/u/s!AlMk_BUOGnOImYtdCSCp6f1MGOu_AQ – jcamacho Oct 05 '16 at 16:58
  • @Camacho I have update my answer please review now your issue is fixed. – Mitul Marsoniya Oct 06 '16 at 06:26
  • 2
    and thanks to Indian developer community, this isn't first time that you help me with an iOs question on stackoverflow, thank you so much! – jcamacho Oct 06 '16 at 08:39
  • Welcome :) Happy coding :) – Mitul Marsoniya Oct 06 '16 at 08:58
  • Hi, is there any way to do this without getting rid of the tab bar's shadow as well? When I did this, it worked, but the tab bar's shadow also disappeared. – Ethan Zhao Jun 20 '19 at 15:18
  • @EthanZhao Sorry i don't know other way. – Mitul Marsoniya Jun 21 '19 at 04:04
9

Working Solution as of iOS 13.3

// remove top line
if #available(iOS 13.0, *) {
    // ios 13.0 and above
    let appearance = tabBar.standardAppearance
    appearance.shadowImage = nil
    appearance.shadowColor = nil
    appearance.backgroundEffect = nil
    // need to set background because it is black in standardAppearance
    appearance.backgroundColor = .someColor
    tabBar.standardAppearance = appearance
} else {
    // below ios 13.0
    let image = UIImage()
    tabBar.shadowImage = image
    tabBar.backgroundImage = image
    // background
    tabBar.backgroundColor = .someColor
}
mkz
  • 2,302
  • 2
  • 30
  • 43
  • This answer should be the correct one, because the answer marked as correct changes the color of the tabbar when applies the appearance. – Diego Jiménez Jan 10 '21 at 19:23
8

Tested on iOS 14

override func viewDidLoad() {
    // Remove default border line
    tabBar.shadowImage = UIImage()
    tabBar.backgroundImage = UIImage()
    tabBar.backgroundColor = UIColor.white
}
denis_lor
  • 6,212
  • 4
  • 31
  • 55
8

For iOS 13

if (@available(iOS 13.0, *)) {
    UITabBarAppearance *appearance = [self.tabBarController.tabBar.standardAppearance copy];
    appearance.shadowImage = nil;
    appearance.shadowColor = nil;
    self.tabBarController.tabBar.standardAppearance = appearance;
}
gnoix
  • 81
  • 1
  • 2
5

This works for me @iso13:

AppDelegate.swift

UITabBar.appearance().clipsToBounds = true
UITabBar.appearance().shadowImage = nil

or

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

or

UITabBar.appearance().clipsToBounds = true
UITabBar.appearance().layer.borderColor = UIColor.clear.cgColor
kironet
  • 766
  • 2
  • 11
  • 27
2

For iOS 10 changed tabbar style to black did the trick

self.tabBarController.tabBar.shadowImage = UIImage()
self.tabBarController.tabBar.barStyle = .Black
Hamdan Javed
  • 309
  • 4
  • 3
2

You can do it this way in your FirstViewController.swift:
Swift 4.2

self.tabBarController!.tabBar.layer.borderWidth = 0.50
self.tabBarController!.tabBar.layer.borderColor = UIColor.clear.cgColor
self.tabBarController?.tabBar.clipsToBounds = true

Just change border color as you want.

Mashood Murtaza
  • 477
  • 5
  • 14
1

You should implement the following two methods at the same time:

[[UITabBar appearance] setShadowImage:[UIImage new]];
[[UITabBar appearance] setBackgroundImage:[UIImage new]];
BabyFish
  • 11
  • 2
1

It's a shadow image (property) of tabbar. Try following solutions and see.

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

Krunal
  • 77,632
  • 48
  • 245
  • 261
1

I don't have the reputation to comment but to add to gnoix's answer, I had a slightly different problem in that I wanted the shadow and the background clear so I had in Swift

if #available(iOS 13.0, *) {
    let appearance = tabBar.standardAppearance.copy()
    appearance.configureWithTransparentBackground()
    tabBar.standardAppearance = appearance
} else {
    tabBar.backgroundColor = UIColor.clear
    let image = UIImage(ciImage: CIImage(color: CIColor.clear)).af_imageAspectScaled(toFit: tabBar.bounds.size)
    tabBar.backgroundImage = image
    tabBar.shadowImage = image
}
Andrew
  • 689
  • 5
  • 6
  • `appearance.configureWithTransparentBackground()` works for me as I have shadow on tabBar layer as well. – Yuan Fu Oct 04 '19 at 23:23
  • Question is about removing just the topline of the tabbar and not about making tabbar background transparent. – sahiljain Oct 11 '19 at 11:43
0

I had the same problem in ios 10. I fixed this issue just changing the height of UITabBar (by default is 49). Check it here how to change the height.

Community
  • 1
  • 1
Alexander Karpov
  • 530
  • 1
  • 7
  • 16
0

If you create your own subclass of UITabBarController, you can set the values in viewDidLoad like this

Swift 3

override func viewDidLoad() {
        super.viewDidLoad()
        self.tabBar.layer.borderWidth = 0
        self.tabBar.clipsToBounds = true
}
TaeVitae
  • 9
  • 1
0

As for me, the solution with tabBar appearance didn't work because it ignored my tabBar.itemPositioning = .centered in that case.

The thing that works for me is tabBar.barStyle = .black.

And don't forget to set tabBar.backgroundColor = .white or any other color your prefer.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
0

If you are using storyboard thats an way On tab bar controller, select the "tab bar"

Like in this image

and then add an runtime attribute "clipsToBounds" bool:

like in this image

fcdt
  • 2,371
  • 5
  • 14
  • 26