TTStyledText 中的 URL 和图像
您好,我创建了一个 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;
我的 [content objectForKey:@"content"]
的 NSLog 返回如下内容:
<a href="http://www.abc.com/">Download-Link</a>
我的链接在我的标签中突出显示,但它们不可点击。
我在 UIViewController 中的 - (void)viewDidLoad
中初始化了我的文本标签
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/">Download-Link</a>
My Links are highlighted in my label, but they are unclickable.
i initialized my textlabel in - (void)viewDidLoad
in a UIViewController
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您将 url 添加到 TTURLMap,它也会打开相关的控制器,
以下代码片段应该可以工作
//edit
因此,如果您使用 TTNavigator,您可能需要在 URLMap 中映射“*”,例如:
这将映射TTWebController 的所有 url 将打开一个 web 视图进行浏览
if you'll add the url to TTURLMap it will also open the relevant controller
the following code snippet should work
//edit
So you probably need to map "*" in the URLMap if you are using the TTNavigator, something like:
this will map all of the urls to the TTWebController which will open a webview to browse in
我有同样的问题。尝试使用
它对我有用。
I've same problem.Try to use
It's work for me.