Я сделал для себя приложение для работы, чтобы отправить мне полную документацию по заказу на обслуживание, но я хочу иметь жирный текст до + random.text! так что легче читать.
Примеры:
messageBody + = "\ nFöretag:" + kundForetag.text! = Företag: Google.se <- Как это выглядит сейчас <br>messageBody + = "\ nFöretag:" + kundForetag.text! = Foretag: Google.se <- я хочу, чтобы это выглядело так в почте. Где "Företag:" - жирный текст </p>
Кто-нибудь может мне помочь?
import MessageUI
import UIKit
class ViewController: UIViewController, MFMailComposeViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
// Bara light mode
overrideUserInterfaceStyle = .light
// Fixar så att textView ser ut som textField
grindInformation.layer.cornerRadius = 5
grindInformation.layer.borderColor = UIColor.gray.withAlphaComponent(0.5).cgColor
grindInformation.layer.borderWidth = 0.5
grindInformation.clipsToBounds = true
}
// Göm keyboard när manrör utanför text area
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.view.endEditing(true)
}
// Göm keyboard när man trycker på retur
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return (true)
}
// KUND INFORMATION
@IBOutlet weak var kundForetag: UITextField!
@IBOutlet weak var kundOrgnr: UITextField!
@IBOutlet weak var kundMarkning: UITextField!
@IBOutlet weak var kundAdress: UITextField!
@IBOutlet weak var kundStad: UITextField!
@IBOutlet weak var kundPostnummer: UITextField!
@IBOutlet weak var kundKontakt: UITextField!
@IBOutlet weak var kundTelefon: UITextField!
@IBOutlet weak var kundEpost: UITextField!
// GRIND INFORMATION
@IBOutlet weak var grindTyp: UITextField!
@IBOutlet weak var grindTid: UITextField!
@IBOutlet weak var grindMil: UITextField!
@IBOutlet weak var grindInformation: UITextView!
@IBOutlet weak var grindCE: UITextField!
// SERVICETEKNIKER / SUBJECT
@IBOutlet weak var teknikerSubject: UITextField!
// Skicka Iconen = Genererar mailet
@IBAction func sendEmail(_ sender: UIButton) {
// Modify following variables with your text / recipient
let recipientEmail = "mail@randommail.com"
let subject = "Ny serviceorder av: " + teknikerSubject.text!
// KUND INFORMATION
var messageBody = "- Företags Information -"
messageBody += "\nFöretag: " + kundForetag.text!
messageBody += "\nOrganisationsnummer: " + kundOrgnr.text!
messageBody += "\nFakturamärkning: " + kundMarkning.text!
messageBody += "\nAdress: " + kundAdress.text!
messageBody += "\nStad: " + kundStad.text!
messageBody += "\nPostnummer: " + kundPostnummer.text!
messageBody += "\nKontakt: " + kundKontakt.text!
messageBody += "\nTelefon: " + kundTelefon.text!
messageBody += "\nE-post: " + kundEpost.text!
// GRIND INFORMATION
messageBody += "\n\n- Order Detaljer -"
messageBody += "\nGrind: " + grindTyp.text! + " (CE)" + grindCE.text!
messageBody += "\nMil: " + grindMil.text!
messageBody += "\nTid: " + grindTid.text!
messageBody += "\n\n"
messageBody += "\n" + grindInformation.text!
messageBody += "\n\n"
// Show default mail composer
if MFMailComposeViewController.canSendMail() {
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setToRecipients([recipientEmail])
mail.setSubject(subject)
mail.setMessageBody(messageBody, isHTML: false)
present(mail, animated: true)
// Show third party email composer if default Mail app is not present
} else if let emailUrl = createEmailUrl(to: recipientEmail, subject: subject, messageBody: messageBody) {
UIApplication.shared.open(emailUrl)
}
}
// Om mail inte är installerat så väljer den någon av följande mail app. Om ingen av dessa finns så ber appen dig att installera Mail appen.
private func createEmailUrl(to: String, subject: String, messageBody: String) -> URL? {
let subjectEncoded = subject.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!
let messageBodyEncoded = messageBody.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!
let outlookUrl = URL(string: "ms-outlook://compose?to=\(to)&subject=\(subjectEncoded)&body=\(messageBodyEncoded)")
let gmailUrl = URL(string: "googlegmail://co?to=\(to)&subject=\(subjectEncoded)&body=\(messageBodyEncoded)")
let yahooMail = URL(string: "ymail://mail/compose?to=\(to)&subject=\(subjectEncoded)&body=\(messageBodyEncoded)")
let sparkUrl = URL(string: "readdle-spark://compose?recipient=\(to)&subject=\(subjectEncoded)&body=\(messageBodyEncoded)")
let defaultUrl = URL(string: "mailto:\(to)?subject=\(subjectEncoded)&body=\(messageBodyEncoded)")
if let outlookUrl = outlookUrl, UIApplication.shared.canOpenURL(outlookUrl) {
return outlookUrl
} else if let gmailUrl = gmailUrl, UIApplication.shared.canOpenURL(gmailUrl) {
return gmailUrl
} else if let yahooMail = yahooMail, UIApplication.shared.canOpenURL(yahooMail) {
return yahooMail
} else if let sparkUrl = sparkUrl, UIApplication.shared.canOpenURL(sparkUrl) {
return sparkUrl
}
return defaultUrl
}
func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
controller.dismiss(animated: true)
}
}