代码之家  ›  专栏  ›  技术社区  ›  Naresh

如何将uitab条位置更改为顶部?

  •  -1
  • Naresh  · 技术社区  · 7 年前

    我有两个视图控制器,嵌入了标签栏控制器。它工作正常,但我想展示 tabbar 框架在视图顶部。我把镜框换到上面了,效果也不错。但问题在底部,它显示了一些 whitecolor 底部视图 塔巴 位置。

    See the bottom view on this pic

    我的代码是

    viewDidLoad

    //Set selected item colour white on tab bar
    UITabBar.appearance().tintColor = UIColor.white
    //Set tab bar title position
    UITabBarItem.appearance().titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -12.5)
    //Tab bar title font
    UITabBarItem.appearance().setTitleTextAttributes([kCTFontAttributeName as NSAttributedStringKey: UIFont.boldSystemFont(ofSize: 15.0)], for: .normal)
    
    
    
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        //Set tab bar frame on top position
        tabBar.frame = CGRect(x: 0, y: 0, width: tabBar.frame.size.width, height: tabBar.frame.size.height)
    //        tabBar.isTranslucent = false
    }
    
    override func viewWillAppear(_ animated: Bool) {
        //Set navigation bar translucent
        navigationController?.navigationBar.isTranslucent = false
    }
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Naresh    7 年前

    我在故事板中添加了背景图片视图,这就是我遇到这个问题的原因。我删除了故事板中的图像视图,并通过编程添加了背景图像。

    let imageView = UIImageView(image: UIImage(named: hdpi.png")!)
    imageView.frame = CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height)
    view.insertSubview(imageView, at: 0)
    

    现在我的问题解决了…