6

Anyone have a working solution to get rid of this border in iOS 10? I have a custom UITabBar background image.

I've tried the following with no results:

tabBar.backgroundImage = UIImage(named: "myBackgroundImage.png")
tabBar.shadowImage = nil
tabBar.shadowImage = UIImage()
// i've also tried combinations of this in the storyboard directly

I finally threw my hands up in the air and set the bar style to "Black".. this doesn't get rid of the border, but makes it white. So it hides it.

thin border at top

skippyman
  • 91
  • 1
  • 4

4 Answers4

6

If you use backgroundImage then shadow line will come so you can try this :

self.tabBar.backgroundImage = UIImage()
self.tabBar.shadowImage = UIImage()
let tabBarView = UIImageView(image: #imageLiteral(resourceName: "YOUR_IMAGE"))
tabBarView.frame = CGRect(x: 0, y: 49 - IMAGEHEIGHT, width: SCREENWIDTH, height: IMAGEHEIGHT)
self.tabBar.addSubview(tabBarView)
self.tabBar.sendSubview(toBack: tabBarView)

It work for me

Tej
  • 71
  • 1
  • 4
  • Hi Tej, I had a similar problem and I was stuck for a few days about implementing a tabbar with a custom image, but your answer worked! Thank you so much. I thought when we add a custom background image to the tab bar, we use tabBar.backgroundImage with custom image, but I guess I'm not correct. I was wondering why we don't specify the custom image in tabBar.backgroundImage = UIImage() and add subview to the tabBar with a custom UIImageView? https://stackoverflow.com/questions/70284002/tab-bar-wont-appear-until-a-collection-view-reaches-out-the-top-of-the-tab-bar – Yuuu Dec 10 '21 at 03:29
  • I mean.. I understand we add subview to the tabbar so it appears on the tabbar, but why we should not specify the custom image at the .backgroundImage property? – Yuuu Dec 10 '21 at 03:29
1

This was happening to me because my image was taller than the default tab bar of 49. Making sure my background image height was exactly 49 made this line disappear (96 for 2x and 147 for 3x).

Hope it helps!

JAB
  • 3,165
  • 16
  • 29
0

Try this:

tabBar.layer.borderWidth = 0
tabBar.layer.borderColor = .clear
Timmy
  • 537
  • 3
  • 10
  • No luck. I just tried this, still shows up: `tabBar.layer.borderWidth = 0 tabBar.layer.borderColor = UIColor.clearColor().CGColor` – skippyman Jan 04 '17 at 20:03
0

Are you sure there is no border in the image itself?

Manni84
  • 11
  • 1
  • Yes, it is not in the image. When I adjust the bar style to "Black", the border remains but it's white (as expected). That would prove that it's not a part of the background image itself. – skippyman Jan 05 '17 at 06:58
  • Try this: UITabBar.appearance().layer.borderWidth = 0.0 UITabBar.appearance().clipsToBounds = true – Manni84 Jan 05 '17 at 19:30
  • This chops off the top portion of the UITabBar background image. It removes the border, technically... but removes everything above ~49 points on the device. And thank you for your continued effort on this! – skippyman Jan 06 '17 at 00:45