Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


iOS 6.0 crash on boundingRectWithSize: #217

kubbing opened this Issue · 20 comments

7 participants


Hi in XCode 4.5, iOS 6.0 beta4,

I thing there is a problem with NSAttributedString generation The following code crashes on the last line.

NSString *htmlString = @"Ooooh, Mr. Protagonist(s)";

NSData *htmlData = [htmlString dataUsingEncoding:NSUTF8StringEncoding];
NSAttributedString *string = [[NSAttributedString alloc] initWithHTMLData:htmlData
CGRect rect = [string boundingRectWithSize:CGSizeMake(300, 0) options:0 context:NULL];

With some weird bug.

-[__NSCFType lineBreakMode]: unrecognized selector sent to instance 0x1edda590
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType lineBreakMode]: unrecognized selector sent to instance 0x1edda590'

I'd like to help, but I have no idea what could cause the problem.


I bypassed the crash by commenting out default values in - (BOOL)_buildString in DTHTMLAttributedStringBuilder.m.

But still I do not get the correct size from the method. There is one line only :/. I must be something missing…


The boundingRectWithSize is part of iOS 6 which is not currently compatible with DTCoreText.

For example this might have trouble with the pre-iOS-6-style attributes.

It might expect the font to be specified as UIFont.


Kubbing could you post the code you used to bypass this crash? I am seeing it consistently on iOS 6.0


please try again with my latest additions. There is a new option to make the output compatible with iOS 6 UITextViews: 46d2910


This appears to have solved the problem... thanks!

Just remember to add the following in your options dictionary:

[NSNumber numberWithBool:YES], DTUseiOS6Attributes

It would be great if this tip was included in the setup guide, that is, have the smoke test use initWithHTML:options:documentAttributes instead of initWithHTML:documentAttributes.


@magmatic if you feel some addition is helpful then please provide it via pull request.


I ´m getting the same Problem. On iOS 6 it crashes with an Error:

-[__NSCFType lineBreakMode]: unrecognized selector sent to instance

My Code looks like this:

NOTICE: I´m using DTAttributeTextView

NSString *html = item.text;

NSData *data = [html dataUsingEncoding:NSUTF8StringEncoding];

CGFloat fontSizeMultiplier = 1.33;
CGFloat const DTCoreTextDefaultFontSize = 12.0;
NSString * fontName = @"Helvetica";

NSMutableDictionary *options = [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithFloat:fontSizeMultiplier], NSTextSizeMultiplierDocumentOption,
                                fontName, DTDefaultFontFamily,
                                @"purple", DTDefaultLinkColor,
                                @"red", DTDefaultLinkHighlightColor,
                                [NSNumber numberWithBool:YES],DTUseiOS6Attributes,

NSAttributedString *attrString = [[NSAttributedString alloc] initWithHTMLData:data options:options documentAttributes:nil];

NSLog(@"%@", attrString);

     self.textView.attributedString = attrString;
     self.textView.userInteractionEnabled = NO;

 CGSize size = CGSizeMake(320,CGFLOAT_MAX);

     CGRect sizeCalculation = [attrString boundingRectWithSize:size
                                                 options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading)

self.textView.contentSize = CGSizeMake(320, sizeCalculation.size.height);
[self addSubview:self.textView];

     CGRect messageFrame = self.textView.frame;
     messageFrame.size.height = self.textView.contentSize.height;
     self.textView.frame = messageFrame;


-boundingRectWithSize:options:context cannot be used with DTCoreText since this is a method by Apple.


Any Idea how i can calculate the correct size (specially the height) of my text which comes from an api?


Are you sure that it's the -boundingRectWithSize:options:context line that causes this error? I use the same method with the same options and it works fine on both iOS 6 and 7.


The error occurs on the line : context:nil]; of boundingRectWithSize..... The Error occurs only on iOS 6, not on iOS 7...

I need another Method for the size Calculation...its really a bad problem in my app...


You need to enable iOS6 tags via parsing option to have an NSAttributedString that is compatible with iOS 6. You get the needed size by creating a DTCoreTextLayoutFrame and inspecting the frame property


Sry for my silly question, but is there any Demo about how to use DTCoreTextLayoutFrame? I´m not sure how tu use it?


You are write: "If you specify CGFLOAT_HEIGHT_UNKNOWN the height will be calculated."

Do you mean it will be calculated automtically if i implement "CGFLOAT_HEIGHT_UNKNOWN" ??

I tried to implement the Code, but Xcode can´t find:
to calculate the correct size....

Whats the problem? I also tried to import "DTCoreTextLayoutFrame.h"


Those constants are defined in #import <DTCoreText/DTCoreTextConstants.h>


Thanks for the tip! but i still cant find the two needed constants. I searched the whole DTCoreTExt Project for: CGFLOAT_WIDTH_UNKNOWN

but i cant find them anywhere??


@Fosile , the same for me. I'm using cocoapods 1.6.8 version. But there is an update and 1.6.9 version is now available, and these constants are present there.


Ok now i found the constants, thank you very much for that! It works now as expected :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.