请注意,在您将其标记为重复之前,请注意,我已经阅读了此文,并且似乎不适用于
然后它会被显示为这样:
![enter image description here](https://istack.dev59.com/sL8SM.webp)
所以它也没有如预期那样显示。这里的目标是像这样显示:
![enter image description here](https://istack.dev59.com/oCL5s.webp)
如何设置约束来显示
UITabBar
。
UIViewController
和UITabBar
都是以编程方式创建的。 约束条件设置如下:public override func viewDidLoad() {
super.viewDidLoad()
self.view.bringSubview(toFront: self.tabBar)
}
关于self.tabBar
:
lazy var tabBar: UITabBar = {
let tab = UITabBar()
self.view.addSubview(tab)
tab.translatesAutoresizingMaskIntoConstraints = false
tab.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true
tab.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true
tab.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true //This line will change in second part of this post.
return tab
}()
这个展示像这样的UITabBar
:
由于它没有考虑安全区域,所以太小了。因此,我更改了以下行:
tab.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
to:
tab.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor).isActive = true
然后它会被显示为这样:
![enter image description here](https://istack.dev59.com/sL8SM.webp)
所以它也没有如预期那样显示。这里的目标是像这样显示:
![enter image description here](https://istack.dev59.com/oCL5s.webp)
如何设置约束来显示
UITabBar
?
UITabBarController
。添加UITabBar
有什么问题吗? - JakubUITabBarController
和UITabBar
,但我并不需要大多数UITabBarController
的功能。UITabBar
没有任何问题。正如苹果文档所述:通常,你会使用 UITabBarController 对象来配合使用选项卡栏,但你也可以将其作为独立控件在你的应用程序中使用。
- Jakub