これはそれを行う必要があります。
let textField = UITextField()
view.addSubview(textField)
textField.translatesAutoresizingMaskIntoConstraints = false
// center horizontally
textField.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
// 100 from top layout guide
textField.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor, constant: 100).isActive = true
// make sure textfield width never exceeds the superview width
textField.leftAnchor.constraint(greaterThanOrEqualTo: view.leftAnchor).isActive = true
textField.rightAnchor.constraint(lessThanOrEqualTo: view.rightAnchor).isActive = true
// give the textfield its default width, notice the lowered priority which allows this constraint to be broken when needed to satisfy the above constraints
let widthConstraint = textField.widthAnchor.constraint(equalToConstant: 370)
widthConstraint.priority = UILayoutPriorityDefaultHigh
widthConstraint.isActive = true
質問者が提供した詳細に基づいて、私はこの回答が正しいとは思わない(実際には逆転している)。私の答えは、私の言いたいことを参照してください。 – Dima
さて、私はそれを試しました、そして、私はそれが5SとiPadシミュレータに期待しているように働いているようです!たぶん私は問題を誤解しました! – Rikh
実際、私が言ったことを取り戻します。私はあなたの答えを誤って読んで、最後の部分で '<'を逃しました。あなたも正しいです!これは、同じ結果を達成するもう1つの方法です。 – Dima