If you read a string from an XML file, the line break \n
in this string will not work in UILabel
text. The \n
is not parsed to a line break.
Here is a little trick to solve this issue:
// correct next line \n in string from XML file
NSString *myNewLineStr = @"\n";
myLabelText = [myLabelText stringByReplacingOccurrencesOfString:@"\\n" withString:myNewLineStr];
myLabel.text = myLabelText;
So you have to replace the unparsed \n
part in your string by a parsed \n
in a hardcoded NSString
.
Here are my other label settings:
myLabel.numberOfLines = 0;
myLabel.backgroundColor = [UIColor lightGrayColor];
myLabel.textColor = [UIColor redColor];
myLabel.font = [UIFont fontWithName:@"Helvetica Neue" size:14.0];
myLabel.textAlignment = UITextAlignmentCenter;
Most important is to set numberOfLines
to 0
(= unlimited number of lines in label).
No idea why Apple has chosen to not parse \n
in strings read from XML?
UILabel
doesn't have aorigin
norsize
property on iOS? It should probably belabel.frame.origin.x
etc. – Cerium