【发布时间】:2018-10-22 00:53:07
【问题描述】:
这是我写的代码
let topViewa = UIView()
topViewa.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(topViewa)
topViewa.backgroundColor = .white
topViewa.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 300).isActive = true
topViewa.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: 0).isActive = true
topViewa.frame.size = CGSize(width: screenWidth, height: 44)
let fw = UILabel(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
fw.backgroundColor = .red
topViewa.addSubview(fw)
screenWidth 是屏幕的宽度。
当我运行它时,这就是我得到的
为什么我没有得到白色背景的父 UIView?
【问题讨论】:
标签: swift uiview autolayout constraints