試試這個gever):
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"before after"];
NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
textAttachment.image = [UIImage imageNamed:@"download.jpeg"];
CGFloat oldWidth = textAttachment.image.size.width;
CGFloat scaleFactor = oldWidth/(self.textField.frame.size.width - 10);
textAttachment.image = [UIImage imageWithCGImage:textAttachment.image.CGImage scale:scaleFactor orientation:UIImageOrientationUp];
NSAttributedString *attrStringWithImage = [NSAttributedString attributedStringWithAttachment:textAttachment];
[attributedString replaceCharactersInRange:NSMakeRange(6, 1) withAttributedString:attrStringWithImage];
self.textField.attributedText = attributedString;
ü不能傳遞圖像文本框...當前鍵盤的擴展只能通過一個普通的NSString主機應用程序。有些人使用NSPasteboard來交換數據,但是這需要主機應用程序來執行「粘貼」。 – Helix 2014-11-09 08:44:44
同意@Helix,你不可以。「kik」所做的是,使用'UITextField'上方的單獨視圖來插入圖像仔細觀察。 – Peter 2014-11-09 13:42:17