iPhone Formatted Strings
I would like to be able to format a string in a label or textfield so that i can change the font color and size of certain keywo开发者_JAVA百科rds. does anyone know how to do this? is it possible to find the actual physical dimensions of a CharcterSet as well?
Craig Hockenberry from Twitteriffic fame will help you out. Stay away from Three20 if you can. I regret using it sadly, I wish it worked a lot better but I have had far to many issue with it.
The answer is FancyLabels. http://furbo.org/2008/10/07/fancy-uilabels/
Download link http://furbo.org/stuff/FancyLabel_1.0.zip
Attributed strings (NSAttributedString and CFAttributedStringRef, and their mutable variants) are what is commonly used in OS X. They are available in iOS. However, UIKit really isn't employing them at this time.
CoreGraphics.framework and CoreText.framework will be your friends, if you do not find a suitable 3rd party solution. PDFs or HTML could also be useful in some cases, and displayed easily.
If you really want to, then render it on your own using CoreText. Simply build an NSMutableString and pass it to a renderer with just a few lines of code. CoreText is actually quite easy to use. The other option will be to use an UIWebView where you render some styled html. I did a deeper discussion of the problem in a related post, you might want to have a look at it.
I don't know Three 20 in detail. But if others recommend it, it might be worth a look. Besides that it may be way too much power for your purpose and hence might cost too much performance.
Currently, I think the UITextField or UILabel will not allow you to change some text to be a color and the others to be another color. But you can use the Three 20 Style library to accomplish that
inspiration by: Craig Hockenberry from Twitteriffic
fancy-label really gave me a bump wan i was stack, it had a problem with y origins when i was using Japanese and it make me come out with little different solution.
code might be little dirty ;) but it works use it and let me know of improvments or gave me suggestions how to improve thx.
textViewProject
Have a look at https://github.com/Cocoanetics/NSAttributedString-Additions-for-HTML
This allows you to easily create NSAttributedString instances from simple HTML for custom-rendering.
精彩评论