As the comment says, you should use UITextView, not UITextField.
UITextField handles only a single line.
Use UITextView to process multiple lines of text.
I'm going to give you an opinion on number 3.
First, there is something that limits the length
of the textview.
Auto-layout to a length of 25 characters to fit the font size you want.
The second is that when the text reaches 25 characters, it adds a line-breaking symbol
.
extension mainVC: UITextViewDelegate {
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
if let char = text.cString(using: String.Encoding.utf8) {
let isBackSpace = strcmp(char, "\\b")
if isBackSpace != -92 {
if textView.text.count == 25 {
textView.text += "\n"
}
}
}
return true
}
}
If what you entered is not backspace
, it will be executed. If it's 25 characters, you can add the line symbol '\n'
to the text in textView and change it.