iOS 6 多行标签行距

标签 ios uilabel

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/

相关文章:

ios - 如何在 iOS 应用程序的相机中添加当前时间戳

ios - Swift - UITextView 不显示文本

iphone - CTLine 有 "string access"是什么意思?

objective-c - 在具有下标的 UILabel 上调用方法 sizeToFit 不起作用

ios - 如何以编程方式为按钮生成按钮名称

ios - SwiftUI 根据设备设置 navigationViewStyle

ios - 在转换应用程序中构建数据

ios - 如何覆盖 iOS 中图像的自动重新定位?

xamarin.ios - Interface Builder 看不到我的子类 UILabel

swift - 随着我的 UILabel 尺寸的增加,在它周围获得额外的空间