您如何使用TTStyledTextLabel? [英] Just how to you use TTStyledTextLabel?

查看:107
本文介绍了您如何使用TTStyledTextLabel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的只是在我的viewController中显示一些简单的文本,并自动进行超链接。当用户点击链接时,我希望控件以某种方式进行回调,我可以使用URL执行某些操作。我怎样才能做到这一点?

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?

我已经查看了TTCatalog几个小时。我也尝试查看three20的源代码以及查看堆栈跟踪。没有帮助。我只是无法弄清楚我的应用程序如何对URL的点击做出反应。请问有什么提示吗?

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?

推荐答案

如果没有看到你已经尝试过的东西,很难提供帮助,但你应该可以做类似的事情以下内容:

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

然后您可以使用 TTNavigator TTURLMap custom-uri:// some / url 映射到应用程序中的特定控制器,或者在您的应用程序中自行处理申请代表。查看如何执行此操作的最佳位置是查看Three20源中包含的 TTNavigatorDemo 示例应用程序。具体来说,请查看 AppDelegate.m 是执行所有URL映射的地方。

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.

这篇关于您如何使用TTStyledTextLabel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆