1

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?

Romes
  • 3,088
  • 5
  • 37
  • 52
  • I think that `stringWithFormat`is used to create a new string from more than just a string (integers, floats). As far as I know it has nothing to do with style. Perhaps try [NSAttributedString](https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/nsattributedstring_Class/Reference/Reference.html) – Majster May 08 '12 at 15:54
  • I think it works fine with ARC. Or you can use two UILabel with different color text. Btw, i think NSAttributedString should be used accompany with Core text. AliSoftware's OHAttributedLabel also implement the core text. You have to import CoreText.framework in your App. – lu yuan May 09 '12 at 18:21

3 Answers3

1

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

Community
  • 1
  • 1
lu yuan
  • 7,207
  • 9
  • 44
  • 78
  • I've added the CoreText.framework to my App. I don't want to use Ali's way of doing it, there has got to be a standard NSAttributeString way of doing it. I just don't know how to structure the code. – Romes May 09 '12 at 19:25
  • UILabel,UITextView doesnot support NSAttributedStrin. You can try UIWebView. – lu yuan May 10 '12 at 02:21
1

NSStrings don't know about fonts. Have a look at NSAttributedString and Core Text. References:

Community
  • 1
  • 1
Hailei
  • 42,163
  • 6
  • 44
  • 69
0

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.

tronbabylove
  • 1,102
  • 8
  • 12