gpt4 book ai didi

ios - 将图像添加到 UITextView

转载 作者:行者123 更新时间:2023-11-29 12:39:07 25 4
gpt4 key购买 nike

似乎之前有人问过这个问题但没有回答过,但这个问题很古老,从那以后已经有很多 Xcode/iOS 更新,所以我要试一试。

我有一个简单的 View Controller 布局。有一个包含只读 TextView 的 View ,其中包含一些有关如何使用该应用程序的说明。我想在滚动 TextView 中穿插一些图像,以引用我在说明中提到的按钮和其他元素。

这是 View :

enter image description here

因此,例如,当说明提到绿色开始按钮时,我想插入该按钮的图像与其余文本内联。

我正在使用 Xcode 5.1.1,当然还有 Storyboard。在此先感谢您的任何建议。

最佳答案

您可以使用 NSAttributedStringNSTextAttachment 将图像附加到文本

NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"press   to start"];
NSTextAttachment *imageAttachment = [NSTextAttachment new];
imageAttachment.image = [UIImage imageNamed:@"AnyImage.png"];
NSAttributedString *stringWithImage = [NSAttributedString attributedStringWithAttachment:imageAttachment];
[attributedString replaceCharactersInRange:NSMakeRange(5, 1) withAttributedString:stringWithImage];

self.textView.attributedText = attributedString;

关于ios - 将图像添加到 UITextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25502047/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com