複数行のテキストでラベルをプログラム的に配置したいと思っています。私はそれを次の制約に加えましたが、ただ一つの行に表示されています!画面の境界を越えずに複数の行を表示するにはどうすればよいですか?Swiftに複数行のテキストを含むUILabelをどのように配置するのですか?
let noResults = UILabel()
noResults.text = self.emptyMessage
noResults.lineBreakMode = .byWordWrapping
noResults.minimumScaleFactor = 0.5
noResults.textAlignment = .center
noResults.font = UIFont(name: "Montserrat-Light", size: 20.0)!
noResults.numberOfLines = 0
noResults.adjustsFontSizeToFitWidth = true
noResults.sizeToFit()
noResults.textColor = UIColor.lightGray
noResults.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(noResults)
let yConstraint = NSLayoutConstraint(item: noResults, attribute: .centerY, relatedBy: .equal, toItem: noResults.superview, attribute: .centerY, multiplier: 1, constant: -(self.navigationController?.navigationBar.frame.height)!)
let xConstraint = NSLayoutConstraint(item: noResults, attribute: .centerX, relatedBy: .equal, toItem: noResults.superview, attribute: .centerX, multiplier: 1, constant: 0)
NSLayoutConstraint.activate([yConstraint, xConstraint])
あなたが受け入れられたとして、私はそれに印を付けます回答としてこれを追加した場合の幅 – CZ54
を制限する制約を追加します。 – stevenpcurtis
ありがとうございました! – CZ54