Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 10: Custom UITabBar background image produces border at top of image. How do I remove it?

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

like image 995
skippyman Avatar asked Jan 04 '17 17:01

skippyman


2 Answers

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

like image 104
Tej Avatar answered Sep 28 '22 08:09

Tej


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!

like image 45
JAB Avatar answered Sep 28 '22 07:09

JAB