作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
嗨,我创建了一个 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/
嗨,我创建了一个 TTStyledTextLabel,效果很好。 现在我想让 URL 可点击,我已经这样做了: textLabel.text = [TTStyledText textFromXHTML
我是一名优秀的程序员,十分优秀!