Reputation: 928
In TTTAttributedLabel
, \r\n
is counted as 2 line endings while it should be only one. UILabel handle this case correctly.
Example: This is the string @"Line 1\r\nLine 2"
. The top one is TTTAttributedLabel
, bottom one is UILabel
Xcode project file: http://tinywhale.net/TestProject.zip
Any idea how to make TTTAttributedLabel behaves like UILabel in this case?
Upvotes: 0
Views: 1286
Reputation: 9600
I'm sure you know exactly what's the problem. I am also with you, I suffered the same reason. for a almost two weeks i tried out to solve the problem. Googling and looking Apple's documentation and looking the stackoverflow, I've looked everywhere, could not get a clear answer. In UILabel property "text(NSString)" is \ r \ n and comes up with two consecutive \ n applies only. but CustomLabel property "attributedText(NSAttributedString)" is \ r \ n When both are applied successively.So my solution \ r \ n and occurrence of two consecutive \ r has been replaced with a null string.
NSString *string = [myString stringByReplacingOccurrencesOfString:@"\r" withString:@""];
NSAttributedString *attributedString = [NSAttributedString attributedStringWithString:string];
In fact, @ "Line 1 \ r \ n Line 2" If you check the NSLog have interesting facts.
NSLog(@"Line 1\r\nLine 2");
In Simulator
2012-08-05 23:18:59.170 SimpleTest[30721:707] Line 1
Line 2
In Device
2012-08-05 23:18:59.170 SimpleTest[30721:707] Line 1
Line 2
As you can see above, the simulator and the device \ r's processing is different. For this reason, I did a whole lot of effort.I do not know exactly what, armv7 and this is about the difference between i386 processing. but i think if a bug or a kind of NSString and NSAttributedString also think that these relationships.
My answer to solve your problem I really hope it might help to you.
Upvotes: 1