Re: Subclassing UItextview
Re: Subclassing UItextview
- Subject: Re: Subclassing UItextview
- From: Conrad Shultz <email@hidden>
- Date: Sat, 04 Jun 2011 10:26:15 -0700
On Jun 4, 2011, at 7:22, Fritz Anderson <email@hidden> wrote:
>
> UITextView does not render multiple styles, nor offer link-like behavior. To subclass, you'd have to rip out most of the implementation. If you want those things, use UIWebView, which is what the other apps (at least the ones written by sane people) are doing. Convert the hash-tags to <a> content, with a CSS class for special rendering, and your own URL scheme for capturing your special action for touches.
An app I wrote had need for similar functionality and I went the webview route at first. Unfortunately, UIWebView has a number of drawbacks that make it less than ideal.
In my case there was an inevitable small but noticeable delay before it would render contents, even locally loaded HTML. This bug may be fixed now - I haven't checked.
A bigger problem for something like a Twitter app, one that I never resolved, is how to size reasonably when presented with HTML to render. In my case I wanted a webview that was effectively the -sizeThatFits. Unfortunately AFAICT there is no way to calculate this until after the view finished loading, which resulted in the view briefly "snapping" to size. I considered rendering off screen to workaround this issue, but IIRC UIWebView played some games to suppress off screen rendering (presumably for performance). I ended up using NSString's UIKit additions to estimate size (since I had a finite set of known fonts in the webview) but this failed from time to time due to minute rendering differences between UIWebView and Core Graphics.
Finally, depending on how many webviews you use, you might massacre the performance of UITableView scrolling.
For these various reasons I ended up scrapping UIWebView in favor of various home-brewed substitutes. Since this was in the pre-Core Text days, I ended up using a combination of layered UILabel subviews and directly drawn NSStrings. I am in the process of migrating this fairly messy implementation to Core Text which should resolve all the above and provide a cleaner implementation.
UIWebView has the not insignificant virtue of being easy; Core Text is not for the faint of heart. (The aforementioned obsolete solution was one of my first challenges in Cocoa that didn't have a nice book implementation. And boy did I have to learn a lot for a noob.)
I should note that I do not believe that most other Twitter apps are using UIWebView. For example, there is Loren Brichter's original post re: string drawing and view compositing in Tweetie-now-Twitter:
http://blog.atebits.com/2008/12/fast-scrolling-in-tweetie-with-uitableview/
IIRC, Twitterrific also uses a similar (if not identical) approach.
If you are looking for something not UIWebView (but which has its own set of headaches, particularly bloat) you can check out the Three20 library. I have used its TTStyledText system (which incorporates link handling) for quick and dirty solutions in the past.
Good luck (and others on the list: please chime in if UIWebView has evolved greatly and my concerns are unfounded).
(Sent from my iPhone.)
--
Conrad Shultz
www.synthetiqsolutions.com_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden