Search code examples
iosnsparagraphstyle

how to set NSMutableParagraphStyle firstLineHeadIndent for just first paragraph


I want set firstLineHeadIndent for only first paragraph for a multi-paragraph UILabel, how can I do

NSMutableParagraphStyle *paragraphStype = [[NSMutableParagraphStyle alloc] init];
paragraphStype.firstLineHeadIndent = 10.0f;
[att addAttribute:NSParagraphStyleAttributeName value:paragraphStype range:NSMakeRange(0, att.length)];

Solution

  • Try to use smaller range:

    NSMutableParagraphStyle *paragraphStype = [[NSMutableParagraphStyle alloc] init];
    paragraphStype.firstLineHeadIndent = 10.0f;
    [att addAttribute:NSParagraphStyleAttributeName value:paragraphStype range:NSMakeRange(0, 10)];