Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-04-2010, 11:35 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 2
Default How to Multiple Colors in String?

I have a table row view with a header and a couple of table rows.

How do I vary the color of the text within the strings without using a WebViewController?

If I need rich text, can I use the table row view for say the first three levels and then the WebViewController for the last level in the tree?

Lets say the bottom layer has the following:

Header - Best books
Table Row 1 - Best books for travel in America.
Table Row 2 - Best books for travel in Europe.
Table Row 3 - Best books for cooking.

So in this example, I would like the text in the table rows to be marked up as follows:

Table Row 1 - Best books for travel in America.
Table Row 2 - Best books for travel in Europe.
Table Row 3 - Best books for cooking.

So to make the table row information quicker to scan I have done the following:
Made Best books lighter in color since the exact words are already stated in the header.
Made America, Europe & cooking in Orange since these are the words that are different in each sentence. This way the user can quickly see which table row they would like to select.

The data is being pulled from CoreData and is working right now except for not being able to figure out how to make different parts of the string different colors based on a comparison between two or three table rows and the section header.

Any ideas as to direction? I can write the code but just don't know where to start? Ideas would be greatly appreciated!

Last edited by aharding; 03-04-2010 at 11:35 PM. Reason: Colors didn't take
aharding is offline   Reply With Quote
Old 03-05-2010, 02:12 AM   #2 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,578
Default

I found no easy way to do this. As far as I can tell, you are going to have to draw them yourself to get them different colors.
JasonR is offline   Reply With Quote
Old 03-05-2010, 05:07 AM   #3 (permalink)
Registered Member
 
kelvinkao's Avatar
 
Join Date: Jul 2009
Location: Los Angeles
Posts: 352
Send a message via AIM to kelvinkao
Default

Yeah, there's no easy way to do this. You either will have to implement several UILabels of different colors on top of each other (if the text is simple enough that you can actually figure out the width and position of each word), or you use the web view along with HTML.
kelvinkao is offline   Reply With Quote
Old 03-05-2010, 10:28 AM   #4 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 2
Unhappy

I'm going to have around 20,000 different phrases, each phrase anywhere from three to fifteen words. When you select two or more, that is when the comparison would happen and the words get colored.

Can I use HTML and CSS markup on the fly?
Can the HTML be the bottom layer of the four layer UITableView?

Figuring out positioning of each of the words individually and then laying them out seems daunting on 20,000 different phrases.

We also won't know which words to color and therefore their position until two rows are selected and we compare the words in each phrase.

JasonR, when you say draw, are these words or graphics?

kelvinkao, I don't think I could figure out width and position unless I indexed all 100,000+ words and added a width component to each? Also would need to add, is this the 1st word, 2nd word, 3rd word in the phrase for assembly?

Can the web view and HTML be the bottom layer as asked above? Am I giving up anything by doing this? I have a custom graphic as the background layer of the table view rows which change color when the user places a checkmark in the row. Can the web view look the same as the tableviewrow even though it's not? It needs to look the same to the user.

Everyone else, fell free to chime in! Someone has had to have done this already?!

Last edited by aharding; 03-05-2010 at 10:38 AM. Reason: Ask Questions
aharding is offline   Reply With Quote
Old 03-05-2010, 01:24 PM   #5 (permalink)
Super Moderator
 
Join Date: Oct 2009
Location: San Diego, CA
Posts: 1,578
Default

Luckily for me, my design partner and I decided the colored text wasn't necessary. Because the only way I saw to do what you are describing was to use the low level Quartz 2D functions to draw the text. (Look up Quartz 2D Programming Guide in your documentation if you want to read about it.) I was going insert a special character into the text, and when I found it, manually change the color as I was drawing the letters.

I never did it, but I don't see any reason it wouldn't work. Other than the time it will take to implement. If you can find a way to make UIWebView work, you might consider it.
JasonR is offline   Reply With Quote
Old 03-05-2010, 04:51 PM   #6 (permalink)
Registered Member
 
kelvinkao's Avatar
 
Join Date: Jul 2009
Location: Los Angeles
Posts: 352
Send a message via AIM to kelvinkao
Default

This might help.
Search and highlight text in UIWebView – iCab Blog
kelvinkao is offline   Reply With Quote
Reply

Bookmarks

Tags
color, css, markup, strings

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 234
16 members and 218 guests
ADY, Alsahir, cacao, dacapo, Dani77, Desert Diva, djohnson, F_Bryant, HemiMG, jansan, M@realobjects, MarkC, prchn4christ, smethorst, spiderguy84
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,882
Threads: 89,228
Posts: 380,762
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jansan
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:54 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0