views:

34

answers:

1

Hey All, I know this is a silly doubt but I just want to make sure before I implement in this project. Please help....I have a NSDictionary with a string object in it. String is concatenated with 4fields. I am trying to display this string on the Detail View Controller in UITableView on iphone.

For example my String is formatted as follows:

MR. ZZZ XXX TTT RRR HHH

Now when I am displaying the above string I want the first line to be in bold and the rest of the lines in Italic fonts. As this is a NSDictionary of strings I tried to use string method to get the index of the string but in my case the position keeps on changing as these values are coming from the database.

I will be waiting for ur replies..please..

+1  A: 

Couple ideas, since there is no single UIKit control that can display multiply-styled text natively:

  1. Stylize your string with HTML and load it into a UIWebView
  2. Use two different UILabel objects: the first one is bolded, and the second one is italicized.
  3. Write your own UIView subclass that uses the CoreText framework to draw the stylization yourself

I recommend #2, followed by #1, with #3 being "do this if you're a masochist".

Dave DeLong
#3 is actually easy if going with system fonts and when line breaks are not important.And with TableView performance *might* be important, #3 is fast, #2 not much overhead, #1 is maybe too heavy weight already.
Eiko
Thanks for the reply. I tried doing the option#2 but how to split the fields from my string as I said the indexes keeps on changing..I am sorry if I sound silly but I just started learning iphone apps
racharambola
You don't need CoreText; you can use -[NSString drawInRect:withFont:] and friends.
tc.