简体   繁体   English

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

[英]Tab bar - adding a new beam to all controllers

Example

Has anyone got an example of doing something like that? 有没有人做过这样的例子? I want it to be displayed all the time while passing between other controllers. 我希望在其他控制器之间传递时始终显示它。 I do not want to create it again in every controller. 我不想在每个控制器中再次创建它。

Override TabBar controller's view did load, to create your beamView: 确实覆盖了TabBar控制器的视图,以创建您的beamView:

let beamViewHeight:CGFloat = 60

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

add constraint to align it bottom, top of the tab bar: 添加约束以使其在选项卡栏的底部,顶部对齐:

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])

it look's like this: 它看起来像这样: 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM