标签文本目前在一个奇怪的中心列中构建自己,但我希望它能在屏幕上延伸出来我可以对约束做出哪些更改?
func setupViews() {
self.view.addSubview(lblTitle)
lblTitle.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 150).isActive=true
lblTitle.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive=true
lblTitle.widthAnchor.constraint(equalToConstant: 250).isActive=true
lblTitle.heightAnchor.constraint(equalToConstant: 250).isActive=true
}
let lblTitle: UILabel = {
let lbl=UILabel()
lbl.text="Spicy jalapeno bacon ipsum dolor amet picanha porchetta pork loin short loin turducken biltong."
lbl.textColor=UIColor.black
lbl.textAlignment = .left
lbl.font = UIFont.systemFont(ofSize: 30)
lbl.adjustsFontSizeToFitWidth = true
lbl.numberOfLines=0
lbl.sizeToFit()
lbl.translatesAutoresizingMaskIntoConstraints=false
lbl.minimumScaleFactor = 0.1
return lbl
答案 0 :(得分:3)
您使用此约束将标签的宽度设置为250:
lblTitle.widthAnchor.constraint(equalToConstant: 250).isActive=true
将该值更改为您想要的宽度。