我已经创建了一个小应用程序,以便使用swift在IOS上获取剪贴板,但是当我尝试发布该变量时,它没有显示为字符串,而是显示为<UILabel: 0x146db1a30; frame = (78.6667 229; 257 147); text = 'I'm on my way right now'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x146db1fd0>>
代替\(clipText)
我必须获取剪贴板内容的代码是
let pasteboardString:String? = UIPasteboard.generalPasteboard().string
clipText.text = pasteboardString`
当我使用此代码发布推文时
let tweetController = SLComposeViewController(forServiceType: SLServiceTypeTwitter)
tweetController.setInitialText("Here's what was on my clipboard:(clipText)")
我从顶部得到了文本。
Image of the code I get instead of (clipText)
最佳答案
let pasteboardString:String? = UIPasteboard.generalPasteboard().absolutString
clipText.text = "\(pasteboardString)"
但是您不需要发布UILabel该消息是正确的,因为您正在尝试发布UILabel对象。而不是尝试仅发布字符串或UILabel的文本
代替
"\(clipText)"
使用"\(clipText.text)"
关于ios - 推文未将变量显示为字符串?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33227792/