views:

980

answers:

2

Hi i created a TTStyledTextLabel, works well.

Now i want to make URL clickable, i've done this:

textLabel.text = [TTStyledText textFromXHTML:[content objectForKey:@"content"] lineBreaks:YES URLs:YES];

but my links are still unclickable. Do i have to setup a UIWebView first? Where to declare it?

Another thing is, is it possible to resize Images inside my TTStyledTextLabel to fit them to the Label Size?

Thanks in advance

// edit

what i have exactly done:

textLabel = [[TTStyledTextLabel alloc] initWithFrame:CGRectMake(0.0f, 70.0f, 320.0f, 297.0f)];
textLabel.contentInset = UIEdgeInsetsMake(20, 15, 20, 15);
textLabel.font = [UIFont systemFontOfSize:14];
textLabel.text = [TTStyledText textFromXHTML:[content objectForKey:@"content"] lineBreaks:YES URLs:YES];
[textLabel sizeToFit];
//CGFloat height = textLabel.height;
[scrollView addSubview:textLabel];
scrollView.contentSize = textLabel.frame.size;

an NSLog of my [content objectForKey:@"content"] returns something like this:

<a href="http://www.abc.com/"&gt;Download-Link&lt;/a&gt;

My Links are highlighted in my label, but they are unclickable.

i initialized my textlabel in - (void)viewDidLoad in a UIViewController

+2  A: 
the [content objectForKey:@"content"] should return data containing <a href="url">string to display</a>

if you'll add the url to TTURLMap it will also open the relevant controller

the following code snippet should work

self = [super init];
TTStyledTextLabel* label = [[[TTStyledTextLabel alloc]   initWithFrame:CGRectMake(0, 0, 320, 230)] autorelease];
label.text = [TTStyledText textFromXHTML:@"<a href=\"aa://link1\">link</a> text" lineBreaks:YES URLs:YES];
[label setFont:[UIFont systemFontOfSize:16]];
[[self view] addSubview:label];

//edit

So you probably need to map "*" in the URLMap if you are using the TTNavigator, something like:

TTNavigator* navigator = [TTNavigator navigator];

navigator.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[navigator.window makeKeyAndVisible];

TTURLMap* map = navigator.URLMap;
[map from:@"*" toViewController:[TTWebController class]];

this will map all of the urls to the TTWebController which will open a webview to browse in

Guy Ephraim
thats exactly what i have done, check the edit of my first post.
choise
okay, so i realised that i have to initialize a TTNavigator and a TTURLMap also. i did this and my Links are working now. but i cannot go backward when im in a TTWebController. is there a trick to go back or animate it to my curren Navigation Controller?
choise
I had the same problem, however I've discovered that I've over tried to do it and this caused the problem, unfortunately I don't remember what I've done. It should work of of the box, so try removing unnecessary code, I'll try to remember what I've done
Guy Ephraim
I think the problem was the window property in the navigator try to set it.navigator.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];[navigator.window makeKeyAndVisible];
Guy Ephraim
i replaced my "standard" UIWindow with this navigator.window. but this has also no effect.in my App Delegate im adding a TabBarController to my Window.
choise
this is how it looks like: http://screenr.com/jDx
choise
I've had a similar problem, in only one of my use cases using the TTWebController and after some investigation I've found out that the navigationController of it was nil, as oppose to other cases, however I've got some spec changes so I didn't have to solve it after all. My guess is that finding out what made the navigationController to be nil will solve this issue
Guy Ephraim
A: 

I've same problem.Try to use [navigator setRootViewController:"your main controller"]; It's work for me.

Aleiku