从剪贴板读取字符串

时间:2014-10-15 07:29:50

标签: ios swift

如何从剪贴板中读取字符串并将其写在按钮的标题上?我可以将字符串复制到剪贴板:

UIPasteboard.generalPasteboard().string = "Hello world"

但是如何从剪贴板中读取该字符串并将其分配给String?

1 个答案:

答案 0 :(得分:22)

只需将其读回如下变量:

let pasteboardString: String? = UIPasteboard.general.string
if let theString = pasteboardString {
    print("String is \(theString)")
}