1
votes

I am using given below code to add NSMutableParagraphStyle to a lable, but this code runs fine on iOS7 but gives error on iOS 6. I had also added check but still it crashes the app.

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 ([_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);
   }
}
1
i want that this method should run properly on iOS6 or it should not run due to checks, and why this error is coming - Iqbal Khan
ok let me try tracing it - Raviraj Jadeja
mate this would take time the code also works in ios6.1, i have to download the 6.0 simulator and check on that - Raviraj Jadeja
okay found the problem the i just make the autoshrink of text size for the label to fixed font then it worked - Iqbal Khan

1 Answers

5
votes

try this

    [_precherDetailLabel setAdjustsFontSizeToFitWidth:NO];

maybe even only for iOS6

if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) { //*
       [_precherDetailLabel setAdjustsFontSizeToFitWidth:NO];
}