我怎样才能在iOS中缩进多行UILabel的第一行? [英] How Can I indent only first line of multiline UILabel in iOS?

查看:961
本文介绍了我怎样才能在iOS中缩进多行UILabel的第一行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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;

看起来应如下所示。

推荐答案

@DavidCaunt建议对我有用。我在这里共享代码。

@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];

这篇关于我怎样才能在iOS中缩进多行UILabel的第一行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆