UILabel 中的行间距有问题,我使用的是自定义字体,当我使用表情符号时,两行之间没有空格。这显然看起来不太好。所以我将这段代码用于行间距,但应用程序崩溃并给出错误
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSAttributedString invalid for autoresizing, it must have a single spanning paragraph style (or none) with a non-wrapping lineBreakMode.'
if ([cell.label2 respondsToSelector:@selector(setAttributedText:)])
{
UIFont *font =btMyriadProRegularWithSize14Pt;
NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[paragraphStyle setLineSpacing: 22];
NSDictionary *attributes = @{ NSFontAttributeName: font, NSParagraphStyleAttributeName: paragraphStyle };
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:chatMessage.msgString attributes:attributes];
[cell.label2 setAttributedText: attributedString];
}
else
{
NSString * msg = [NSString stringWithFormat:@"%@: %@",chatMessage.from,chatMessage.msgString];
cell.label2.text = msg;
}
最佳答案
试试这个
[cell.label2 setAdjustsFontSizeToFitWidth:NO];
甚至可能只适用于 iOS6
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) { //*
[cell.label2 setAdjustsFontSizeToFitWidth:NO];
}
关于iOS 6 多行标签行距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22397869/