我怎样才能在iOS中缩进多行UILabel的第一行?

GMJ*_*gar 12 objective-c uilabel ios ios7

我想在UILabel的开头添加一个图像.标签是多行的.如果我使用contentInset,它会缩进整个标签,但我只想缩进第一行.

到目前为止我试过这个,这对我不起作用.

    UIEdgeInsets titleInsets = UIEdgeInsetsMake(0.0, 40.0, 0.0, 0.0);
    valueLabel.contentInset = titleInsets;
Run Code Online (Sandbox Code Playgroud)

它看起来应该是这样的.

在此输入图像描述

GMJ*_*gar 14

@DavidCaunt的建议对我有用.我在这里分享代码.

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

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

[valueLabel setAttributedText:attributedText];
Run Code Online (Sandbox Code Playgroud)