【问题标题】:want to add stickers(similar to emoji) to textview in Xcode 6?想在 Xcode 6 中向 textview 添加贴纸(类似于表情符号)?
【发布时间】:2014-10-14 06:27:07
【问题描述】:

我正在尝试将我的表情符号键盘设为默认键盘。我 想将我的图像(贴纸)添加到 textview。我正在使用 xcode6,它允许将我们的键盘作为所有应用程序的默认键盘。我可以在单击我的贴纸时向 textview 添加文本。但无法将该贴纸添加到我的文本视图。

简而言之,我正在尝试访问 textview 以添加图像。

感谢您的解决方案。提前致谢。

【问题讨论】:

标签: ios objective-c swift xcode6


【解决方案1】:

你需要使用 NSAttributted String:

NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"like after"];

NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
textAttachment.image = [UIImage imageNamed:@"whatever.png"];

NSAttributedString *attrStringWithImage = [NSAttributedString attributedStringWithAttachment:textAttachment];

[attributedString replaceCharactersInRange:NSMakeRange(4, 1) withAttributedString:attrStringWithImage];

来源:iOS 7 TextKit - How to insert images inline with text?

【讨论】:

  • 我使用了下面的代码。它只会添加 1 张图像而丢失了前一张。 [attributedString appendAttributedString:attrStringWithImage];
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-07-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-22
  • 2014-11-01
相关资源
最近更新 更多