How Can I indent only first line of multiline UILabel in iOS?

I want to add an image in start of UILabel. Label is multiline. If I use contentInset, it indent the whole label but I want to indent first line only.

I have tried this so far, this doesn't work for me.

    UIEdgeInsets titleInsets = UIEdgeInsetsMake(0.0, 40.0, 0.0, 0.0);
    valueLabel.contentInset = titleInsets;

It should look like this.

@DavidCaunt suggestion worked for me. I am sharing code here.

NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
style.firstLineHeadIndent = 50;

[attributedText addAttribute:NSParagraphStyleAttributeName value:style range:range];

[valueLabel setAttributedText:attributedText];

How Can I indent only first line of multiline UILabel in iOS?, Note: I am using Rubik-Regular font as a test font that you mentioned in your post​.From your code you only setting headIntent to your first line .If you want to use  While I found how to add indentations to first line (FirstLineHeadIndent) and to the rest of lines (HeadIndent), I cannot find how to add indents to only first two/three lines in order to achieve

As a user716216 pointed, additionally - we can use a tab with defined indent value:

NSMutableParagraphStyle *paragraphStyle = [NSMutableParagraphStyle new];
paragraphStyle.headIndent = 50;

label.attributedText = [[NSAttributedString alloc] initWithString:
    @"\tHow can i add image like this in start of UILabel? Label is multiline.........."
    attributes:@{NSParagraphStyleAttributeName: paragraphStyle}];

Why first line indent on UILabel dont work well with custom font , While I found how to add indentations to first line (FirstLineHeadIndent) and to the rest of lines (HeadIndent), I cannot find how to add indents to only first  I'd like to make a command that indents all text passed as an argument; similarly to this question, but using a command with no alteration to the text required. Something like this: \\def \\

Here's how you can do this in Interface Builder:

How to add indents to Multiple lines of UILabel?, I want to add an image in start of UILabel. Label is multiline. If I use contentInset, it indent the whole label but I want to indent first line only. I have tried this so far,  The first part creates an attributed string with the properties it needs to replicate the behavior of UILabel (might not be 100% but should be close enough). Then we create a framesetter and frame, and get all the lines of the frame, from which we extract the range of the last expected line of the label.

How Can I indent only first line of multiline UILabel in iOS?, NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init]; style.​firstLineHeadIndent = 50; [attributedText  Intrinsic Content Size of Multi-Line Text. The intrinsic content size of UILabel and NSTextField is ambiguous for multi-line text. The height of the text depends on the width of the lines, which is yet to be determined when solving the constraints.

objective c, @DavidCaunt's suggestion worked for me. I am using the code here. NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];  To get to the First Line indent, drop-down the list under "Special" and choose "First Line". Then specify how much of an indent you want in the box to the right of it (usually, 1 cm is fine). If you wanted all paragraphs of that kind to look like that, you would instead use Format>Style to make the same change in the style rather than to just

How can I only indent on the first line of multi-line UILabel in iOS , Use the lineBreakMode property to control how the label splits the text into multiple lines, and the truncation behavior associated with the final line. Use Auto​  Using the titlesec package, you can use your approach: \titleformat{\subsection}[block] {\large\bfseries} {\hspace{1cm}\thesubsection} {1ex}{} but I would like to present you another option, using the runin format (for a run-in title) and then, the first mandatory argument of \titleformat that allows you to specify (in the runin format) the indentation just before the title; a little example

Comments
  • I know this is the right approach, but did you try it with custom fonts. For me it doesnt work.
  • I had to indent 2 rows in one UILabel so I used: paragraphStyle.firstLineHeadIndent = 7; paragraphStyle.headIndent = 7;