【问题标题】:Having trouble with the Tab bar background image标签栏背景图片有问题
【发布时间】:2017-07-09 20:06:18
【问题描述】:

我想显示带有垂直分隔线的标签栏的背景图像。

我有以下分辨率的图像:-

1x - 320 x 49

2x - 640 x 98

3x - 960 x 147

图像在 iPhone 5 上正确设置,分隔线在适当的位置,但在 iPhone 6/7 和 iPhone 6+/7+ 上渲染不正确。

分隔线不在适当的位置,一些重叠的标签栏项目。

注意:我使用的是 Xcode 8.2。

【问题讨论】:

    标签: swift uitabbarcontroller uitabbar uitabbaritem uiimageasset


    【解决方案1】:

    像这样创建一个 UIView 并根据需要设置中心项目的高度。

    然后在 TabbarView 控制器中。将此视图添加到标签栏视图 像这样。

    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)
    

    【讨论】:

      猜你喜欢
      • 2014-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多