petrpavlik / PPLabel

UILabel subclass with detection of touches on individual characters
90 stars 26 forks source link

Attributed text must specify paragraph style #1

Closed emcmanus closed 11 years ago

emcmanus commented 11 years ago

Attributed text instances must currently specify a paragraph style, or else PPLabel will crash in this enumeration block.

A simple test case is to add the following to the example project's ViewController.m#viewDidLoad:

// Works as expected
NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
[paragraph setLineBreakMode:NSLineBreakByWordWrapping];

NSDictionary *attributes = @{NSParagraphStyleAttributeName: paragraph};
self.label.attributedText = [[NSMutableAttributedString alloc] initWithString:@"some string" attributes:attributes];

// Crashes
self.label.attributedText = [[NSMutableAttributedString alloc] initWithString:@"some string" attributes:nil];
petrpavlik commented 11 years ago

Thanks, looking into it.

petrpavlik commented 11 years ago

I pushed a fix to the dev branch.

emcmanus commented 11 years ago

Petr, that must be a record for issue turn-around time. Thanks so much. :smiley:

This certainly solves the test case, but I'm still having issues with a label returning NSNotFound when numberOfLines is 0. Let me poke around for a bit to see if I can either narrow down the conditions for failure or patch the issue.

But I really appreciate the fast response!

petrpavlik commented 11 years ago

Hey, no problem and thanks for trying PPLabel :-). I merged the changes into the master branch so I'm about co close this issue.

About the number of lines issue, the code you pointed at should be executed only if the provided string is empty. Could you open another issue and send me the attributed string that does not work for you? Thanks.

emcmanus commented 11 years ago

Hey Petr, looks to be an issue outside of PPLabel. We're using a custom font and somehow the framesetter and textRectForBounds disagree on the frame size needed to render the attributed string.

As a result, the frame passed to CTFramesetterCreateFrame is 1px too short, and the resulting CTFrameGetVisibleStringRange is [0, 0]. (CTFrameGetStringRange returns the expected [0, length].)