我可以在 UITextView 中使用多种字体样式吗?
我需要在 UITextView 中使用多种字体样式。就像单个 Textview 中的粗体、斜体和下划线文本一样。例如:
第一个单词是粗体,第二个单词可能是斜体,第三个单词是下划线,具体取决于用户的选择。
我不认为这是允许这样做的,但如果有人取得了成就并且想要分享的话。我在输入文本时需要这些,在显示时也需要这些。
谢谢
I have a requirement to use multiple font style in UITextView. Like Bold, Italic and Underline text in single Textview. Like:
One word is Bold second may be italic third Underline as per user selection.
I don't think this is allowed to do but still if any one have achieved and want to share. I need this all while enter text and same while displaying.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你是对的,标准 UITextView 不支持丰富的编辑。目前该问题有几种解决方案。
Omni Group 在开源许可下发布了他们的 iOS 和 Mac 框架。其中包括一个非常强大的富文本编辑器(参见:OUIEditorFrame.m)。它们非常强大,但也极其复杂。他们的示例 iPad 应用程序包括富文本编辑器示例。进一步的讨论可以在此处找到
。 这个人一直在致力于自定义富文本编辑控件,并根据可协商的许可协议提供它。
最后,您可以自己完成这一切并创建一个实现 UITextInput 协议的编辑器控件。除了 Apple 文档之外,此处还提供了一些有关执行此操作的提示。
You're right that the standard UITextView does not support rich editing. At the moment there are a few solutions to the problem.
The Omni Group has released their iOS and Mac frameworks under an open source license. These include a very powerful rich text editor (see: OUIEditorFrame.m). These are very powerful but also extremely complex. Their sample iPad app includes the rich text editor example. Further discussion can be found here
Secondly, this guy has been working on a custom rich text editing control and is offering it under a negotiable licensing agreement.
Finally, you can do it all yourself and create an editor control that implements the UITextInput protocol. Aside from the Apple documentation, there are some tips on doing this here.
为什么不使用属性字符串并使用其属性来设置您喜欢的字符串。
参考链接:https://developer.apple。 com/library/mac/documentation/Cocoa/Conceptual/AttributedStrings/Tasks/CreatingAttributedStrings.html
Why don't you use attributed string and use its property to set the string as you like.
Reference link : https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/AttributedStrings/Tasks/CreatingAttributedStrings.html