我想在按标签时将文字保存到剪贴板。
我已尝试使用UIPasteboard但未被Xcode 7识别
所以基本上我坚持真正的基础:
@IBAction func label1(sender: AnyObject) {
}
答案 0 :(得分:5)
XCode 8和Swift 3代码如下所示,将文本复制到剪贴板:
UIPasteboard.general.string = "this is your text"
答案 1 :(得分:2)
如果只是文本,请使用此代码snipet:
UIPasteboard.generalPasteboard().string = "Label text"
答案 2 :(得分:1)
let pasteBoard = NSPasteboard.generalPasteboard()
pasteBoard.clearContents()
pasteBoard.setString("my string", forType: NSStringPboardType)
答案 3 :(得分:0)
此代码对我有用:
let pasteboard = UIPasteboard.general
pasteboard.string = lableGetPassword.text