标签栏 - 为所有控制器添加新光束

时间:2018-03-31 14:11:51

标签: ios swift xcode swift3 uitabbarcontroller

Example

有没有人有这样做的例子? 我希望它在其他控制器之间传递时始终显示。我不想在每个控制器中再次创建它。

1 个答案:

答案 0 :(得分:0)

覆盖TabBar控制器的视图确实已加载,以创建beamView:

let beamViewHeight:CGFloat = 60

let beamView = UIView()
beamView.translatesAutoresizingMaskIntoConstraints = false
beamView.backgroundColor = .black
self.view.addSubview(beamView)

添加约束以将其对齐到标签栏的顶部:

let bottom = NSLayoutConstraint(item: beamView, attribute: .bottom, relatedBy: .equal, toItem: self.tabBar, attribute: .top, multiplier: 1, constant: 0)
let leading = NSLayoutConstraint(item: beamView, attribute: .leading, relatedBy: .equal, toItem: view, attribute: .leading, multiplier: 1, constant: 0)
let trailing = NSLayoutConstraint(item: beamView, attribute: .trailing, relatedBy: .equal, toItem: view, attribute: .trailing, multiplier: 1, constant: 0)
let height = NSLayoutConstraint(item: beamView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: beamViewHeight)

view.addConstraints([bottom, leading, trailing, height])

它看起来像这样: enter image description here