1

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);
   }
}
shankar
  • 632
  • 4
  • 14
Iqbal Khan
  • 4,587
  • 8
  • 44
  • 83

1 Answers1

5

try this

    [_precherDetailLabel setAdjustsFontSizeToFitWidth:NO];

maybe even only for iOS6

if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) { //*
       [_precherDetailLabel setAdjustsFontSizeToFitWidth:NO];
}
Flori
  • 2,453
  • 1
  • 21
  • 31
  • okay found the problem the i just make the autoshrink of text size for the label to fixed font then it worked – – Iqbal Khan Apr 16 '14 at 08:09