How to change the size of the text programmatically
I use UITextView to display text to the user, this text co开发者_如何学运维ntains titles and subtitles, I need to make the titles size bigger than the subtitles programmatically. How can I do that please?
From the documentation for UITextView
:
The font, color, and text alignment attributes you specify always apply to the entire contents of the text view.
If you want to have richer formatting capabilities, you may want to try UIWebView
. Sadly, this will not have the editing capabilities of UITextView
.
The other option is to overlay UITextView
s with one another, but then alignment may become an issue. Those really are your two best options, though.
UITextView is not a rich text editor. This means that it does not have the ability to save different text attributes over various ranges of the text. It is impossible to change this by any method.
NSAttributedString does have the ability to store rich text. Also, you can draw NSAttributedStrings with core text. If you don't need the text to be editable, just build yourself an appropriate NSAttributedString and let Core Text draw it (Core Graphics under the hood).
Good luck!
Edit: The drawing methods can be found here.
精彩评论