2016-03-07 23 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的鏈接。

相關問題