如何将UITab栏位置改为顶部?

时间:2018-05-30 06:23:20

标签: ios swift uitabbarcontroller uitabbar

我有两个视图控制器并嵌入了标签栏控制器。它工作正常,但我想在视图顶部显示tabbar框架。我将框架改为顶部,它也工作正常。但问题在于它在底部whitecolor位置显示了一些tabbar视图。

如何删除此底部视图? 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 个答案:

答案 0 :(得分:0)

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

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)

现在我的问题解决了......