开发者

Custom UITextView

开发者 https://www.devze.com 2022-12-16 06:54 出处:网络
As posted throughout the web, the only way to display HTML content inside UITextView is by using a private API function setContentAsHTML, and if you use this function you won\'t get your application i

As posted throughout the web, the only way to display HTML content inside UITextView is by using a private API function setContentAsHTML, and if you use this function you won't get your application into the App Store. But there are several word editors which seem to be using UITextView or maybe a custom one made by themselves in their app.

So I needed to ask if it is possible for us to develop our own RichTextView that allows rich text editing and f开发者_运维问答ormatting. Even MFMailComposer has a rich text editor for composing emails.


You can use HTML text in a UITextView, as stated in the docs :

This class does not support multiple styles for text. The font, color, and text alignment attributes you specify always apply to the entire contents of the text view. To display more complex styling in your application, you need to use a UIWebView object and render your content using HTML.

If you are referring to syntax highlighting of HTML, you can use a few different combinations of classes to get the effect you are looking for. Between UITextView, UITextField, UILabel, and UIWebview you can find a few different ways to do this. One nifty trick is to use either UITextField or UITextView as a clearColor input, and render what you want to change in another field that is composed of multiple independently formatted UILabels, or piecewise as UITextViews. There's a lot of ways to skin this cat by being creative.


The reason is that UIKit doesn't support Attributed Text. This may be on it's way... I won't say more on that.

Check out Attributed text for Cocoa on OS X, in a nutshell you have a string and you set a dictionary of styles with ranges and style type (underline, colour, background colour, text alignment etc...) and when this is drawn you end up with "rich text".

For UIKit on iOS at the moment, to display styled text, you have two options, use a UIWebView or use Core Text.

Core Text may seem like an overkill but it will allow you to do so much with the text...

Hope this helps somewhat.

0

精彩评论

暂无评论...
验证码 换一张
取 消