我试图看看我如何在我的UITabBarController下添加一个UIView,这样我就可以在我的应用程序中添加广告了,我似乎无法找出任何方法将我的UIView限制在标签栏的底部。这可能吗?
编辑:标签栏的底部是指标签栏下方
答案 0 :(得分:5)
试试这个添加请参阅:
按照以下步骤实现目标:
UIViewController
Container View
UIViewController
AdView
Container view
UITabbarController
Container view
醇>
答案 1 :(得分:1)
我能够在我的UITabBarController中创建一个UIView
lazy var bannerAd: UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
view.backgroundColor = .black
return view
}()
然后将它固定在底部,如下所示:
view.addSubview(bannerAd)
bannerAd.heightAnchor.constraint(equalToConstant: 44).isActive = true
bannerAd.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
bannerAd.widthAnchor.constraint(equalTo: self.view.widthAnchor).isActive = true
然后向上移动Tab Bar我这样做了:
override func viewWillLayoutSubviews() {
if !didStyleTabBar {
self.tabBar.invalidateIntrinsicContentSize()
var tabFrame = self.tabBar.frame
tabFrame.size.height = tabBarHeight
tabFrame.origin.y = tabFrame.origin.y - 44
self.tabBar.frame = tabFrame
didStyleTabBar = true
}
}