W Dyson
W Dyson

Reputation: 4634

Make portion of NSString italicized or bold, not whole string

How would I go about italicizing a single word in an NSString which will be displayed in a UILabel? Specifically, I don't want all text to be italicized, just one word.

Thanks!

(Edited) I meant UILabel, not UITextField.

Upvotes: 1

Views: 2198

Answers (3)

KingofBliss
KingofBliss

Reputation: 15115

Use NSAttributedString... Find controllers to draw NSAttributedString,since UILabel wont support NSAttributedString

Controller for NSAttributedString

Upvotes: 0

JJ Rohrer
JJ Rohrer

Reputation: 2741

I don't think that what you are asking to do is possible (I'd be happy to be proven wrong). However, this library (https://github.com/facebook/three20/) is a popular way to achieve the same result in a UILabel (not text field) . The library works fairly well, but does have a lot of limitations, especially on edge conditions, and of course, it comes with associated overhead.

I'd encourage you to think about other ways of achieving the same user outcome. Can Placeholder text help? How about hints next to your text field?

Good luck.

Upvotes: 2

Robert Höglund
Robert Höglund

Reputation: 10070

A native UILabel does not support NSAttributedString which is what is normally used to display strings with formatting. You could try an output the text your self using Core Text but I would suggest checking out FontLabel or the three-20 project mentioned by @JJ Rohrer

Upvotes: 1

Related Questions