如何将工具栏附加到底部iOS Swift

时间:2018-07-27 16:17:49

标签: swift uitabbar uitoolbar

我有一个带有标签栏和导航栏的问题。我需要在工具栏的顶部显示一个工具栏,但该工具栏位于最底部。

现在我明白了:

enter image description here

我的代码是:

  private func showToolBar() {
    tabBarController?.tabBar.isHidden = true
    navigationController?.setToolbarHidden(false, animated: true)

    let archiveButton = UIBarButtonItem(image: #imageLiteral(resourceName: "deactivateIcons"), style: .plain, target: self, action: #selector(archive))
    let flexibleSpace = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: self, action: nil)
    let refreshButton = UIBarButtonItem(image: #imageLiteral(resourceName: "changeStatusIcons"), style: .plain, target: self, action: #selector(refresh))
    archiveButton.tintColor = Colors.Purple
    refreshButton.tintColor = Colors.Purple

    setToolbarItems([archiveButton, flexibleSpace, refreshButton], animated: true)

    navigationController?.toolbar.setShadowImage(UIImage(), forToolbarPosition: .bottom)

}

因此工具栏恰好显示在选项卡栏的顶部。如何解决呢?预先感谢!

1 个答案:

答案 0 :(得分:0)

尝试一下:

将该代码放入showToolBar()函数的最后一行

let screenSize: CGRect = UIScreen.main.bounds navigationController?.toolbar.frame = CGRect(x: 0, y: screenSize.height - tabBarHeight - 50, width: screenSize.width, height: 50)