0

Suppose I have text like this in a label

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.

How do I change the colour of the the sentence "At vero eos et..." starting in the second line?

0

2 Answers 2

1

I don't believe this is possible with the UILabel class. However, it wouldn't be too hard to do this with some simple HTML in a UIWebView.

[myWebView loadHTMLString:@"Some normal text. <font color=\"red\">Some red text.</font>" baseURL:nil]

Let me know if this works well for you.

Sign up to request clarification or add additional context in comments.

Comments

1

You can't do that with a standard UILabel. You'd either have to use multiple UILabels or take a look at CoreText which would also do what you want - http://developer.apple.com/library/mac/#documentation/StringsTextFonts/Conceptual/CoreText_Programming/Introduction/Introduction.html.

2 Comments

can I just highlight certain text (say one sentence) and have a specific colour for that?
No, you can't do that with a UILabel. You need to either construct the layout yourself with multiple UILabels (which would be a pain for the layout you're describing), use CoreText or as @josh-rosen points out, use a web view.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.