gpt4 book ai didi

iphone - TTStyledText 中的 URL 和图像

转载 作者:行者123 更新时间:2023-12-03 20:49:26 25 4
gpt4 key购买 nike

嗨,我创建了一个 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 中初始化了我的文本标签

最佳答案

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

如果您将网址添加到 TTURLMap,它也会打开相关 Controller

下面的代码片段应该可以工作

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,该 Controller 将打开一个 Web View 进行浏览

关于iphone - TTStyledText 中的 URL 和图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2276635/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com