I'm trying to create an app whereby the user can send an email with an image attachment of their choice, I've done this so far with UITextfield. What ever the user types in the Text Field it is also included in the email.
My code is as follows:
@IBOutlet var fullName: UITextField!
@IBOutlet var latestPayslip: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
let tap = UITapGestureRecognizer(target: self, action: #selector(UIInputViewController.dismissKeyboard))
view.addGestureRecognizer(tap)
// Do any additional setup after loading the view.
fullName.addToolBar()
fullName.delegate = self
}
@IBAction func sendEmail(_ sender: Any) {
if MFMailComposeViewController.canSendMail() {
let mail = MFMailComposeViewController()
let emailFullName: String = fullName.text!
mail.mailComposeDelegate = self
mail.setToRecipients([“example@abc.com"])
mail.setMessageBody("<p>FullName: \(emailFullName)</p>", isHTML: true)
mail.setSubject("Application for RTO: ")
present(mail, animated: true)
}
}
private lazy var primaryTextFields: [UITextField] = {
[fullName]
}()
@objc func dismissKeyboard() {
//Causes the view (or one of its embedded text fields) to resign the first responder status.
view.endEditing(true)
}
}