so I am making a textfield programmatically. When I hit the done key in the keyboard the curser goes to the next line and key board does not disappear. I have included all the lines of codes recommened by people to make the keyboard disappear but it didn't work. can someone look at my code and advice me what I need to add? I want to hit the done key and keyboard disappear and curser doesn't go to the next line.
import UIKit
class FirstPage: UIViewController {
let emailText: UITextView = {
let textView = UITextView()
let attributedText = NSMutableAttributedString(string: "Email", attributes: [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 20),NSAttributedString.Key.foregroundColor: UIColor.gray])
textView.backgroundColor = UIColor.clear
textView.attributedText = attributedText
textView.translatesAutoresizingMaskIntoConstraints = false
textView.textAlignment = .center
textView.returnKeyType = .done
textView.resignFirstResponder()
textView.isScrollEnabled = false
return textView
}()
override func viewDidLoad() {
super.viewDidLoad()
emailText.delegate = self as? UITextViewDelegate
view.addSubview(emailText)
emailText.translatesAutoresizingMaskIntoConstraints = false
emailText.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true
}
}