2

嗨,我创建了一个 TTStyledTextLabel,效果很好。

现在我想让 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>

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

- (void)viewDidLoad在 UIViewController中初始化了我的文本标签

4

2 回答 2

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

如果您将 url 添加到 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];

//编辑

因此,如果您使用 TTNavigator,您可能需要在 URLMap 中映射“*”,例如:

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,这将打开一个 webview 来浏览

于 2010-02-17T17:17:47.343 回答
0

我有同样的问题。尝试使用

[navigator  setRootViewController:"your main controller";] 

这对我有用。

于 2010-07-12T09:06:48.367 回答