Badge display issue for right-to-left languages on iOS 7
yoasha opened this issue · 5 comments
There is a display issue when localized language direction is right-to-left. (i.e. Hebrew, Arabic). The reason is that NSMutableParagraphStyle alignment property is set according to the current localization.
The current code is:
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
[paragraph setLineBreakMode:NSLineBreakByClipping];
[__badgeString drawInRect:bounds withAttributes:@{ NSFontAttributeName:font,
NSParagraphStyleAttributeName:paragraph}];
#else
[__badgeString drawInRect:bounds withFont:font lineBreakMode:TDLineBreakModeClip];
#endif
I recommend adding the following line:
paragraph.alignment = NSTextAlignmentLeft;
So final code should look as follows:
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
[paragraph setLineBreakMode:NSLineBreakByClipping];
paragraph.alignment = NSTextAlignmentLeft;
[__badgeString drawInRect:bounds withAttributes:@{ NSFontAttributeName:font,
NSParagraphStyleAttributeName:paragraph}];
#else
[__badgeString drawInRect:bounds withFont:font lineBreakMode:TDLineBreakModeClip];
#endif
I tried your fix
paragraph.alignment = NSTextAlignmentLeft;
but it didn't make any difference.
That's interesting...
Did you successfully reproduce the issue (as it looks in the attached image) before applying my fix? Or did you apply it while badge already looks fine?
Hello yoasha. I applied the fix when encountering the exact same issue when trying the Arabic localization but it didn't make a difference. The problem only occurs in iOS7. Did it work in your case?
Yes it worked. I just verified this again now for both Hebrew and Arabic. I also tested this on both a simulator and a real device (iPhone 5): adding the fix, looks great while commenting the fix, a trimming issue...
Are you sure that the line of the fix is being called? I saw that the fix resides in IFDEF block so I would ensure just to be on the safe side... that the line is indeed being called (by using a breakpoint, or placing NSLog right before or after the fix).
Hello yoasha. You were right, it wasn't entering the condition statement. My minimum deployment was set to 40300 so it never entered the loop. I changed my code to this and it now works. Thanks for the assistance and your solution. Here is my code now:
if([[[UIDevice currentDevice] systemVersion] floatValue]>=7.0){
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
[paragraph setLineBreakMode:NSLineBreakByClipping];
paragraph.alignment = NSTextAlignmentLeft;
[__badgeString drawInRect:bounds withAttributes:@{ NSFontAttributeName:font,
NSParagraphStyleAttributeName:paragraph}];
#if !__has_feature(objc_arc)
[paragraph release];
#endif
//
}
else{
[__badgeString drawInRect:bounds withFont:font lineBreakMode:TDLineBreakModeClip];
}