Romes
Romes

Reputation: 3118

iOS - stringWithFormat change part of the text color

I'm pulling in tweets for my application and I want to be able to format my tweets in a certain way and color. For example, here would be a simple tweet...

"@somename This is a sample tweet from twitter. - 7 hours ago"

Is it possible to take the last part of the string, in this case the "7 hours ago" and change the font / font color?

I'm using stringWithFormat: in order to format in this way:

tweet = [NSString stringWithFormat:@"%@%@", title, time];

But I am unsure if I am able to change the time font and color using this code.

Anyone done this before?

Edit

I've attempted this using AliSoftware's OHAttributedLabel, but I am using ARC and this doesn't seam to be working for me.

Is there a standard "iOS" way of accomplishing this? Maybe using NSAttributedString possibly?

Upvotes: 1

Views: 3826

Answers (3)

lu yuan
lu yuan

Reputation: 7227

You could use Core Text. Maybe the following question would help you Is it possible to set different font in One UIlabel?

You have to import CoreText.framework in your App

Upvotes: 1

tronbabylove
tronbabylove

Reputation: 1102

The font/font color are not inherent attributes of the data type NSString. You could use two separate UILabels, or create a small UIWebView to format the text.

Upvotes: 0

Related Questions