开发者

Syntax highlighting in UITextView?

We all know how Xcode changes the colors of certain parts of our code to tell us what kind of object it is right? (Ex. Blue for numbers, green for comments, etc.)

I was wondering how this was accomplished. I want to do this in a UITextView, but I will make my own classes if I have to. Are there any useful threads or tutorials around that have to do with th开发者_StackOverflow社区is?


UITextView doesn't accept more than one style of text, so syntax coloring isn't possible with the control.

You'll have to do you own displaying and editing with the Core Text framework and the UITextInput protocol.

As for the actual coloring, there are some open source code editors that it might be worth taking a look at, for example Fragaria.

Though it is a Cocoa project, not Cocoa Touch, it should still be of use to you.


I guess you are looking for the Core Text API.

If you want to go beyond the SDK, Oliver Drobnik wrote some articles and code about extending NSAttributedString. Check http://www.cocoanetics.com/2011/01/befriending-core-text/ and https://github.com/Cocoanetics/NSAttributedString-Additions-for-HTML

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜