问题
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.
回答1:
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
回答2:
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:
Try this:
tabBar.layer.borderWidth = 0
tabBar.layer.borderColor = .clear
回答4:
Are you sure there is no border in the image itself?
来源:https://stackoverflow.com/questions/41470206/ios-10-custom-uitabbar-background-image-produces-border-at-top-of-image-how-do