iOS 10: Custom UITabBar background image produces

2019-04-07 22:17发布

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

4条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-04-07 22:25

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!

查看更多
疯言疯语
3楼-- · 2019-04-07 22:36

Try this:

tabBar.layer.borderWidth = 0
tabBar.layer.borderColor = .clear
查看更多
聊天终结者
4楼-- · 2019-04-07 22:37

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

查看更多
啃猪蹄的小仙女
5楼-- · 2019-04-07 22:47

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

查看更多
登录 后发表回答