Wednesday 15 August 2012

ios7 - iOS 7 BUG - NSAttributedString does not appear -



ios7 - iOS 7 BUG - NSAttributedString does not appear -

last week asked question simulator bug nsattributedstring not displaying: ios 7 simulator bug - nsattributedstring not appear

unfortunately appears not simulator bug ios 7 bug. have reproduced issue on iphone 5 device.

the bug appears combination of using nsunderlinestyleattributename & nsparagraphstyleattributename attributes nsattributedstring.

i have tested on 2 ios 7 devices far, , issue has appeared on 1 of them. after have both been upgraded exact same version:

1st iphone 5 ios 7.0 (11a465): text not appear

1st iphone 5 after upgrading 7.0.2 (11a501): text not appear

2nd iphone 5 running ios 7.0 (11a4449d): text displays correctly

2nd iphone 5 after upgrading 7.0.2 (11a501): text not appear

so appears apple introduced bug after ios 7.0 (11a4449d). i've filed bug them , update on response get.

steps reproduce bug

if running ios 7.0.2 should able reproduce bug.

either download , run project on device https://github.com/rohinnz/ios-7-bug---nsattributedstring-does-not-appear

or

1) in xcode 5 create new 'single view application'. phone call whatever.

2) in viewcontroller.m, replace viewdidload method with:

- (void)viewdidload { [super viewdidload]; nsmutableparagraphstyle* paragraph = [[nsmutableparagraphstyle alloc] init]; paragraph.alignment = nstextalignmentcenter; nsattributedstring* attrstr = [[nsattributedstring alloc] initwithstring:@"lorem ipsum dolor sit" attributes: @{nsunderlinestyleattributename:@(nsunderlinestylesingle), nsparagraphstyleattributename:paragraph}]; uilabel* mylabel = [[uilabel alloc] initwithframe:cgrectmake(10, 30, 0, 0)]; mylabel.backgroundcolor = [uicolor greencolor]; mylabel.attributedtext = attrstr; [mylabel sizetofit]; [self.view addsubview:mylabel]; }

3) compile , run on device. depending on version of ios 7, text either display, or not. uilabel's background color display in both cases.

screenshots

iphone 5 ios 7.0 (11a465)

iphone 5 ios 7.0 (11a4449d)

my question

is able reproduce issue on device?

i have found workaround bug. in github code, utilize workaround, this:

nsattributedstring* attrstr = [[nsattributedstring alloc] initwithstring:@"lorem ipsum dolor sit\n" // <--- attributes: @{nsunderlinestyleattributename:@(nsunderlinestylesingle), nsparagraphstyleattributename:paragraph}]; uilabel* mylabel = [[uilabel alloc] initwithframe:cgrectmake(10, 30, 0, 0)]; mylabel.backgroundcolor = [uicolor greencolor]; mylabel.attributedtext = attrstr; [mylabel sizetofit]; mylabel.numberoflines = 2; // <---

i have made 2 changes: i've appended newline character original string, , i've set label's numberoflines 2.

what workaround forcefulness label's text against top of label. seems solve problem. in other words, bug appears stem label's effort vertically center text; if deliberately create text long size of label juggling label's height, numberoflines, , excess newline characters @ end of text, attributed string drawn.

edit i've found workaround along same lines: allow label resize fit text. see code , explanation here: http://stackoverflow.com/a/19545193/341994 in code, same thing opposite end, were: give label fixed width constraint flexible height constraint, , setting own height, label brings top of text against top of itself, , able display text correctly. in other words, way of preventing label centering text vertically, seems trigger bug.

further edit have sense bug may fixed in ios 7.1.

ios7 xcode5 nsattributedstring

No comments:

Post a Comment