我正在使用下面给出的代码将NSMutableParagraphStyle添加到标签,但是此代码在iOS7上运行良好,但在iOS 6上却报错。我也添加了检查功能,但仍然使应用程序崩溃。
由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“NSAttributedString对于自动调整大小无效,它必须具有单个跨接段落样式(或无),并且不具有换行lineBreakMode。”
if ([_precherDetailLabel respondsToSelector:@selector(setAttributedText:)] && NSClassFromString(@"NSMutableParagraphStyle")!=Nil)
{
@try {
NSMutableParagraphStyle *paragrahStyle = [[NSMutableParagraphStyle alloc] init];
[paragrahStyle setLineSpacing:3];
NSMutableAttributedString *attributedString=[[NSMutableAttributedString alloc] initWithString:string];
[attributedString addAttribute:NSParagraphStyleAttributeName
value:paragrahStyle
range:NSMakeRange(0, attributedString.length)];
_precherDetailLabel.attributedText=attributedString;
}
@catch (NSException *exception) {
NSLog(@"exception # 2324 %@",exception);
}
}
最佳答案
尝试这个
[_precherDetailLabel setAdjustsFontSizeToFitWidth:NO];
甚至仅适用于iOS6
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) { //*
[_precherDetailLabel setAdjustsFontSizeToFitWidth:NO];
}
关于ios - “NSAttributedString对于自动调整大小无效,它必须具有单个跨接段落样式(或无)且具有非包装的lineBreakMode。”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20539337/