我试图在UILabel中显示格式正确的HTML文本并成功使用以下代码:
// Create the html body
var attributedHTMLBody = NSAttributedString(data: comment.bodyHTML.dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: false), options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil, error: nil)
// Create the string including the text style
var htmlString = String(format: "<div style='font-size: 16px; font-family: HelveticaNeue-Light;'>%@", attributedHTMLBody.string)
// Create the final text to display
var attributedHML = NSAttributedString(data: htmlString.dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: false), options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil, error: nil)
// Set the text
cell.commentLabel.attributedText = attributedHML
// Find the locations of any links
var mutableLinkArray = NSMutableArray()
var mutableRangeArray = …
Run Code Online (Sandbox Code Playgroud) 我正在使用TTTAttributedLabel(https://github.com/twotoasters/TTTAttributedLabel).在这里,我正确地获得了带有一些可点击文本的标签.
我需要像上面图片中的用户名一样显示我的文字(即没有下划线).我怎么能这样做?
我正在尝试将 TTTAttributedLabel 集成到 UITableViewCell 中。这真的只是一个简单的集成,我想要的只是用 TTTAttributedLabel 替换旧的 UILabel。这就是我所做的。
回到 UITableViewController 子类,包含 TTTAttributedLabel.h,修改(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
如下:
static NSString *CellIdentifier = @"Post";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
TTTAttributedLabel *label = (TTTAttributedLabel *)[cell viewWithTag:801];
label.text = [self.post valueForKey:@"content"];
label.enabledTextCheckingTypes = NSTextCheckingTypeLink;
label.userInteractionEnabled = YES;
label.delegate = self;
return cell;
Run Code Online (Sandbox Code Playgroud)但是链接检测不起作用。这只是纯文本。如何调试我做错了什么?
我正在尝试为我的应用程序编写自动化脚本,我的问题是Xcode UI Automation无法看到TTTAttributedLabel
类的元素.获取完整元素树不会显示这些TTTAttributedLabel
元素的迹象.我正在使用Xcode 6.1.1
我正在使用TTTAttributedLabel,我通常在tableview单元格中使用sizetofit.之后,我在单元格高度计算中使用sizeWithFont.我像这样设置了TTTAttributedLabel.
[self.attributedLabel setText:@"Test\n\n\n\n"];
CGSize contentSize = [self.attributedLabel.text sizeWithFont:self.attributedLabel.font
constrainedToSize:CGSizeMake(CGRectGetWidth(self.attributedLabel.frame), 1000)
lineBreakMode:NSLineBreakByWordWrapping];
[self.attributedLabel sizeToFit];
Run Code Online (Sandbox Code Playgroud)
我注意到身高不同了.我得到了这样的输出.所以我猜这是错的.我可以知道如何解决?我在iOS 8设备上测试.
ios ×5
uilabel ×2
appium ×1
automation ×1
hyperlink ×1
iphone ×1
objective-c ×1
sizetofit ×1
sizewithfont ×1
swift ×1
xcode ×1