2016-03-07 21 views
1

enter image description hereiOS版:的UILabel多行 - 标签的第二行需要先从10个像素

我现在面临一个问题,那就是 - 我有一个标签,如“1 Seibl是由一些公司做了一个软件并可在500美元购买“

当涉及到iPhone 4s,标签打印第二行,第二行开始正好在”1.“。我想给空间/保证金/空间,使标签看起来像编号格式。

+0

后快照。 –

+0

如果没有与UILable一起工作,那么我建议你使用UITextView insted的UILable并设置文本插入像uitextview像 'textView.textContainerInset = UIEdgeInsetsMake(0,0,0,0);' – Vvk

回答

3

试试这个解决方案。它可能会帮助你。

使用您的标签的NSAttributedString,并设置其paragraph styleheadIndent

NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy]; 
style.headIndent = 14; 
NSDictionary *attributes = @{ 
    NSParagraphStyleAttributeName: style 
}; 
NSAttributedString *richText = [[NSAttributedString alloc] initWithString:@"So this UILabel walks into a bar…" attributes:attributes]; 
self.narrowLabel.attributedText = richText; 
self.wideLabel.attributedText = richText; 

结果:

example result

+1

它工作正常。谢谢。 –

1

看看使用TextView来代替,并修改它的textStorage属性来定义一个排除区域,以便插入一条新线。这里有一个到documentation的链接。

相关问题