试试这个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