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
答
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这将打开一个网页视图的在
答
我浏览同样的问题。尝试使用
[navigator setRootViewController:"your main controller";]
这对我很有用。
没人?我必须写的任何事情,我的文字是更好理解? – choise 2010-02-17 10:55:54