Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Just how to you use TTStyledTextLabel?

Tags:

iphone

three20

All I want is to display some simple text in my viewController and have the hyperlinks autoparsed. When the user clicks on the link I want the control to somehow do a callback where I can do something with the URL. How can I achieve this?

I've already looked through the TTCatalog for hours. I have also tried looking into the source code of three20 as well as looking at the stack trace. No help. I just can't figure out how my app can react to the click of the URL. Any hints please?

like image 602
erotsppa Avatar asked Jul 23 '09 14:07

erotsppa


People also ask

How do you apply a label style?

To style the label elements the way they appear in the image in the introduction, you need to use the label element with the "for" attribute. Furthermore, you need to close the label element before adding the "input" element itself. The HTML for the complete form in shown in the illustration.

How do you use style text?

To apply a style: Select the text you want to format, or place your cursor at the beginning of the line. In the Styles group on the Home tab, click the More drop-down arrow. Select the desired style from the drop-down menu. The text will appear in the selected style.

How do you label text?

So, the second rule of thumb for labelling text is to label the easiest examples first. The obvious positive/negative examples should be labelled as soon as possible, and the hardest ones should be left to the end, when you have a better comprehension of the problem.


1 Answers

Hard to help without seeing what you've already tried, but you should be able to do something like the following:

TTStyledTextLabel* label = [[[TTStyledTextLabel alloc] 
        initWithFrame:someFrame] autorelease];
NSString* labelText = @"This should <a href=\"custom-uri://some/url\">work</a>";
label.text = [TTStyledText textFromXHTML:labelText lineBreaks:NO URLs:YES];
[someView addSubview:label];

You can then use TTNavigator and TTURLMap to map custom-uri://some/url to a particular controller in your application, or handle it yourself in your application delegate. The best place to find out how to do that is by looking at the TTNavigatorDemo sample application included in the Three20 source. Specifically, look at AppDelegate.m which is where all the URL mapping gets performed.

like image 105
Nathan de Vries Avatar answered Oct 14 '22 07:10

Nathan de Vries