TTStyledText中的URL和图像

TTStyledText中的URL和图像

问题描述:

嗨,我创建了一个TTStyledTextLabel,效果很好。TTStyledText中的URL和图像

现在我想使URL点击,我已经做到了这一点:

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

,但我的链接仍然无法点击。我必须先设置一个UIWebView吗?在哪里申报?

另一件事是,是否可以调整我的TTStyledTextLabel中的图片大小以适应他们的标签大小?

在此先感谢

//编辑

什么我有完全做到:

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; 

一个的NSLog我[content objectForKey:@"content"]回报是这样的:

<a href="http://www.abc.com/">Download-Link</a> 

我的链接在我的标签中突出显示,但它们无法点击。

我初始化我为textLabel在- (void)viewDidLoad在一个UIViewController

+0

没人?我必须写的任何事情,我的文字是更好理解? – choise 2010-02-17 10:55:54

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

如果你添加的网址TTURLMap它也将打开相关的控制器

下面的代码片段应该工作

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]; 

//编辑

所以你可能需要在URLMap地图“*”,如果你使用的是TTNavigator,是这样的:

TTNavigator* navigator = [TTNavigator navigator]; 

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

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

这将映射所有的URL到TTWebController这将打开一个网页视图的在

+0

这就是我所做的,检查我的第一篇文章的编辑。 – choise 2010-02-17 18:02:17

+0

没问题,所以我意识到我必须初始化一个TTNavigator和一个TTURLMap。我做了这个,我的链接现在正在工作。但是当我在TTWebController中时,我不能后退。有没有什么诀窍可以回到我的当前导航控制器上? – choise 2010-02-17 18:27:27

+0

我有同样的问题,但是我发现我已经试过这样做,这导致了问题,不幸的是我不记得我已经做了什么。它应该工作的框,所以尝试删除不必要的代码,我会尽力记住我已经完成 – 2010-02-17 18:38:50

我浏览同样的问题。尝试使用

[navigator setRootViewController:"your main controller";] 

这对我很有用。