Ios 在messages应用程序中以编程方式编写消息时是否可以换行?
从我的Swift iOS应用程序重定向时,是否可能在短信的默认正文中出现换行符 在SMS消息中创建换行符是完全可能的。它是通过使用escapeIos 在messages应用程序中以编程方式编写消息时是否可以换行?,ios,swift,messages,messageui,Ios,Swift,Messages,Messageui,从我的Swift iOS应用程序重定向时,是否可能在短信的默认正文中出现换行符 在SMS消息中创建换行符是完全可能的。它是通过使用escape\n实现的,如所述。下面的代码演示了如何做到这一点 // Create Message Controller // let messageComposeVC = MFMessageComposeViewController() // Set Its Delegate // messageComposeVC.messageComposeDelegate =
\n
实现的,如所述。下面的代码演示了如何做到这一点
// Create Message Controller //
let messageComposeVC = MFMessageComposeViewController()
// Set Its Delegate //
messageComposeVC.messageComposeDelegate = self
// Set Recipient(s) //
messageComposeVC.recipients = ["555-555-5555"]
// Create Body Text (Note the use of "\n") //
messageComposeVC.body = "This is your message. \nThis is your message on a new line."
// Present Message Controller //
presentViewController(messageComposeVC, animated: true, completion: nil)
更新 您也可以删除转义换行符(
\n
)的使用,只需使用块文本:
// Create Message Controller //
let messageComposeVC = MFMessageComposeViewController()
// Set Its Delegate //
messageComposeVC.messageComposeDelegate = self
// Set Recipient(s) //
messageComposeVC.recipients = ["555-555-5555"]
// Create Body Text (Note the use of an opening and closing """) //
messageComposeVC.body = """
This is your message.
This is your message on a new line.
"""
// Present Message Controller //
presentViewController(messageComposeVC, animated: true, completion: nil)
通过使用“”“
指示文本块,我们可以简单地以视觉方式格式化文本
使用这种创建字符串的方法,我们可以在不使用某些(不是全部)特殊转义字符的情况下将项目放在新行、缩进等位置。我们只需删除转义的换行符(
\n
)在此处,只需将所需文本放在实际的新行上。是否尝试将\n
添加到字符串中?如果使用UILabel显示,是否将其行设置为0(无限制)?