I have a UILabel instance, say mylabel.
What i want to do is like this:
mylabel.text = @"Age\tLimit\tYear";
instead of
mylabel.text = @"Age Limit Year";
But when i tried, \t is not recognized. How to achieve it?
I have a UILabel instance, say mylabel.
What i want to do is like this:
mylabel.text = @"Age\tLimit\tYear";
instead of
mylabel.text = @"Age Limit Year";
But when i tried, \t is not recognized. How to achieve it?
You can also format string first
NSString *formattedString = [NSString stringWithFormat:@"Age%8s%8s",[@"Limit" UTF8String], [@"Year" UTF8String]];
mylabel.text = formattedString;
Unfortunately, %@ formatter doesn't add spaces to adjust field width. So I use UTF8String with %s specifier to adjust width.
Note: Width specifies a minimum number of characters to output, and is typically used to pad fixed-width fields in tabulated output, where the fields would otherwise be smaller, although it does not cause truncation of oversized fields.
Add one more backslash to it so it will be like this.
mylabel.text = @"Age\\tLimit\\tYear";
That way it won't be parsed as tab which is represented as "\t".
Here you have some more info: How do I escape special characters in an NSString using RegexKitLite? And here as well: how to write special character in objective-C NSString