如何在iOS中只缩进多行UILabel的第一行?
我想在UILabel的开始添加一个图像。 标签是多行的。 如果我使用contentInset,它会缩进整个标签,但我只想缩进第一行。
到目前为止我已经尝试过了,这对我不起作用。
UIEdgeInsets titleInsets = UIEdgeInsetsMake(0.0, 40.0, 0.0, 0.0); valueLabel.contentInset = titleInsets;
它应该看起来像这样。
@DavidCaunt的build议为我工作。 我在这里分享代码。
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init]; style.firstLineHeadIndent = 50; [attributedText addAttribute:NSParagraphStyleAttributeName value:style range:range]; [valueLabel setAttributedText:attributedText];
正如user716216指出的那样,另外 – 我们可以使用一个定义了缩进值的标签:
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}];