This question is about implementing text indentation ("The placement of text farther to the right to separate it from surrounding text") in iOS.
Take for example the following text:
Notice that the second row in section 2 begin farther to the right and just below the line above.
My code contains an array of NSString
, each one should be display as a section with numeric bullet like above. for example:
NSArray *array = [NSArray arrayWithObjects:@"1. This is the first section.", @"2. This is the second one, with two lines.", @"3. This is the third.", nil];
I use UILable
to display the text on screen.
To set the text from the array to the label, and to separate each string in a new line I use
myLabel.text = [array componentsJoinedByString:@"\n"];
Any ideas how to get this effect?
Well I decided to implement it my self without using Core Text, I just created a view strcture that make all the indentation work by itself, and let you customize it as you want.
For all of you interested in the implementation, you can see the source code and an example project here:
ECListView Project