Я попытался центрировать позицию X моего текстового поля так, чтобы она находилась в центре моего контроллера просмотра страниц. Вот как я сейчас запрограммировал это:
lastnamefield = UITextField(frame: CGRect(x: 100.33, y:431.33 , width: 206, height: 34))
lastnamefield.backgroundColor = .clear
lastnamefield.placeholder = "Last name"
lastnamefield.textColor = .black
lastnamefield.font = UIFont(name: "Futura", size: 20)
lastnamefield.borderStyle = UITextField.BorderStyle.roundedRect
lastnamefield.autocorrectionType = UITextAutocorrectionType.no
lastnamefield.keyboardType = UIKeyboardType.default
lastnamefield.returnKeyType = UIReturnKeyType.done
lastnamefield.clearButtonMode = UITextField.ViewMode.whileEditing
lastnamefield.contentVerticalAlignment = UIControl.ContentVerticalAlignment.center
// lastnamefield.delegate = self as! UITextFieldDelegate
self.view.addSubview(lastnamefield)
emailfield = UITextField(frame: CGRect(x: 100.33, y:488 , width: 206, height: 34))
emailfield.backgroundColor = .clear
emailfield.placeholder = "Email Adress"
emailfield.textColor = .black
emailfield.font = UIFont(name: "Futura", size: 20)
emailfield.borderStyle = UITextField.BorderStyle.roundedRect
emailfield.autocorrectionType = UITextAutocorrectionType.no
emailfield.keyboardType = UIKeyboardType.default
emailfield.returnKeyType = UIReturnKeyType.done
emailfield.clearButtonMode = UITextField.ViewMode.whileEditing
emailfield.contentVerticalAlignment = UIControl.ContentVerticalAlignment.center
// emailfield.delegate = self as! UITextFieldDelegate
self.view.addSubview(emailfield)
Я знаю, что это, очевидно, не отцентрирует его, но я пробовал что-то вроде этого:
emailfield.widthAnchor.constraint(equalTo: revealingSplashView.widthAnchor, multiplier: 0.8).isActive = true
imageView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor).isActive = true
emailfield.heightAnchor.constraint(equalToConstant: 25).isActive = true
emailfield.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
Мое приложение либо вылетает, либо получаю ошибку. Я немного новичок в этом ограничении, и я должен делать это программно, так как мой pageviewcontroller тоже программно. Я прошу прощения за мои плохие навыки письма. Я не англичанин sh.