在a中点击超链接是微不足道的UITextView.您只需在IB中的视图上设置"检测链接"复选框,它就会检测HTTP链接并将其转换为超链接.
但是,这仍然意味着用户看到的是"原始"链接.RTF文件和HTML都允许您设置一个用户可读的字符串,其中包含一个"后面"的链接.
可以很容易地将属性文本安装到文本视图中(或者,UILabel或者UITextField就此而言).但是,当该属性文本包含链接时,它不可单击.
有没有办法让用户可读的文本可以点击UITextView,UILabel或UITextField?
标记在SO上是不同的,但这是一般的想法.我想要的是这样的文字:
此变形是使用Face Dancer生成的,单击可在应用商店中查看.
我唯一能得到的是:
使用Face Dancer生成此变形,单击http://example.com/facedancer以在应用商店中查看.
我有UITableView和动态大小调整单元格,以HTML格式显示评论列表,我遇到的问题是NSAttributedString渲染HTML内容非常慢!
这是分析器的快照.
我试图将NSAttributedString初始化放到单独的线程中,但仍然很慢并且用户在呈现HTML时看到空单元格,最后在完成呈现单元格时,布局不正确.
dispatch_async(GlobalQueue, {
let html = NSAttributedString(
data: self.comment.htmlBody.dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: false)!,
options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
documentAttributes: nil,
error: nil)
dispatch_async(MainQueue, {
self.commentLabel.attributedText = html
self.commentLabel.font = UIFont(name: "HelveticaNeue-Light", size: 14.0)!
if let writer = self.comment.author {
self.authorLabel.text = writer.name
}
self.layoutIfNeeded()
})
})
Run Code Online (Sandbox Code Playgroud)
请建议如何加快渲染和修复单元格布局.
谢谢!
更新:
使用单元格委托和标志解决,表明属性字符串已初始化.也许会帮助某人:
// TicketCell
private var isContentInitialized = false
private var commentAttributedString:NSAttributedString?
var delegate: TicketCommentCellDelegate?
var indexPath: NSIndexPath!
var comment: TicketComment! {
willSet {
if newValue != self.comment {
self.isContentInitialized = false
} …Run Code Online (Sandbox Code Playgroud) uitableview nsattributedstring grand-central-dispatch ios swift
我有一个UILabel.我想设置一个字符串,其中还包含一些HTML标签.字符串是:
NSString *str = @"<p>Hey you. My <b>name </b> is <h1> Joe </h1></p>";
Run Code Online (Sandbox Code Playgroud)
我怎么能在上面显示这个 UILabel
NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[str dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];
mylabel.attributedText=attrStr;
Run Code Online (Sandbox Code Playgroud)
上面的代码没有显示任何内容.