Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS7 TextKit: bullet point alignment

Tags:

I'm writing an app for iOS 7 only and I'm trying to get decent formatting on bullet points in a non-editable UITextView.

It's easy enough to just insert a bullet point character, but of course the left indentation won't follow. What's the easiest way on iOS 7 to set a left indent after a bullet point?

Thanks in advance,

Frank

like image 693
Frank R. Avatar asked Oct 25 '13 08:10

Frank R.


People also ask

Should bullet points be aligned?

All bullet points should be aligned at the same indent, be the same size, and be the same font. Simple black bullets, while possibly more on the boring side, fit the bill just fine. Having more than two types or stages of bullet points is excessive, visually unappealing, and often difficult to process.


1 Answers

So I've looked around, and here is the extracted minimal code from Duncan's answer to make it work:

NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:yourLabel.text];

NSMutableParagraphStyle *paragrahStyle = [[NSMutableParagraphStyle alloc] init];
[paragrahStyle setParagraphSpacing:4];
[paragrahStyle setParagraphSpacingBefore:3];
[paragrahStyle setFirstLineHeadIndent:0.0f];  // First line is the one with bullet point
[paragrahStyle setHeadIndent:10.5f];    // Set the indent for given bullet character and size font

[attributedString addAttribute:NSParagraphStyleAttributeName value:paragrahStyle
                         range:NSMakeRange(0, [self.descriptionLabel.text length])];

yourLabel.attributedText = attributedString;

And here is the result of that in my app:

Quadratic Master

like image 69
Lukas Petr Avatar answered Sep 21 '22 16:09

Lukas Petr