Malloc
Malloc

Reputation: 16276

How to change the size of the text programmatically

I use UITextView to display text to the user, this text contains titles and subtitles, I need to make the titles size bigger than the subtitles programmatically. How can I do that please?

Upvotes: 1

Views: 309

Answers (2)

Dexter
Dexter

Reputation: 5726

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.

Upvotes: 2

PengOne
PengOne

Reputation: 48398

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.

Upvotes: 3

Related Questions