'NSAttributedString对于自动调整大小无效,它必须具有单个跨越段落样式(或者没有),并带有非换行lineBreakMode.

Iqb*_*han 1 iphone cocoa-touch objective-c ios

我使用下面给出的代码将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);
   }
}
Run Code Online (Sandbox Code Playgroud)

Flo*_*ori 5

试试这个

    [_precherDetailLabel setAdjustsFontSizeToFitWidth:NO];
Run Code Online (Sandbox Code Playgroud)

甚至可能仅适用于iOS6

if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) { //*
       [_precherDetailLabel setAdjustsFontSizeToFitWidth:NO];
}
Run Code Online (Sandbox Code Playgroud)