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
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.
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
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.