Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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

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

Controller for NSAttributedString

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top