开发者

How to change the size of the text programmatically

开发者 https://www.devze.com 2023-03-16 23:30 出处:网络
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 ple

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 UITextViews 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.

0

精彩评论

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