无法使用选项卡栏背景图片
问题描述:
我想显示具有垂直分隔线的选项卡栏的背景图像。无法使用选项卡栏背景图片
我有这样的图像以下列分辨率: -
1X - 320×49
2× - 640×98
3× - 960×147
图像正确地为iPhone 5设置了适当位置的分隔线,但未正确呈现iPhone 6/7和iPhon e 6 +/7 +。
分隔线不在适当的地方,一些重叠的标签栏项目。
答
创建一个UIView像这样,并设置中心项目的高度为你的愿望。
然后在TabbarView控制器。将此视图添加到Tabbar View像这样。
UITabBar.appearance().shadowImage = UIImage()
customNavBar = NSBundle.mainBundle().loadNibNamed("CustomTabBarView", owner: self, options: nil)[0] as! UIView
bdNavBar.translatesAutoresizingMaskIntoConstraints = false
self.tabBar.addSubview(customNavBar)
然后将约束添加到自定义Tabbar。
self.view.addConstraint(NSLayoutConstraint(item: customNavBar, attribute: .Left, relatedBy: .Equal, toItem: self.view, attribute: .Left, multiplier: 1.0, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: customNavBar, attribute: .Right, relatedBy: .Equal, toItem: self.view, attribute: .Right, multiplier: 1.0, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: customNavBar, attribute: .Bottom, relatedBy: .Equal, toItem: self.view, attribute: .Bottom, multiplier: 1.0, constant: 0))
bdNavBar.addConstraint(NSLayoutConstraint(item: customNavBar, attribute: NSLayoutAttribute.Height, relatedBy: .Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1.0, constant: 50))
self.tabBar.bringSubviewToFront(customNavBar)