swift 如何用纯代码给控件添加约束?

如题,我想在主视图中创建一个吸底的子视图,但是为子视图添加了约束后,这个子视图完全没有被渲染出来。想问下是我哪里出了问题?以下是我的代码:

let bottom_view = UIView()
bottom_view.frame.size.width = self.view.frame.size.width
bottom_view.frame.size.height = 56
bottom_view.backgroundColor = .red
self.view.addSubview(bottom_view)

bottom_view.translatesAutoresizingMaskIntoConstraints = false
let bottomConstraint = NSLayoutConstraint.init(item: bottom_view, attribute: .bottom, relatedBy: .equal, toItem: bottom_view.superview, attribute: .bottom, multiplier: 1.0, constant: 0)
 bottom_view.superview!.addConstraint(bottomConstraint)
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!

社区文档: