iOS版:的UILabel多行 - 标签的第二行需要先从10个像素
我现在面临一个问题,那就是 - 我有一个标签,如“1 Seibl是由一些公司做了一个软件并可在500美元购买“
当涉及到iPhone 4s,标签打印第二行,第二行开始正好在”1.“。我想给空间/保证金/空间,使标签看起来像编号格式。
iOS版:的UILabel多行 - 标签的第二行需要先从10个像素
我现在面临一个问题,那就是 - 我有一个标签,如“1 Seibl是由一些公司做了一个软件并可在500美元购买“
当涉及到iPhone 4s,标签打印第二行,第二行开始正好在”1.“。我想给空间/保证金/空间,使标签看起来像编号格式。
试试这个解决方案。它可能会帮助你。
使用您的标签的NSAttributedString
,并设置其paragraph style的headIndent
:
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;
结果:
它工作正常。谢谢。 –
看看使用TextView
来代替,并修改它的textStorage
属性来定义一个排除区域,以便插入一条新线。这里有一个到documentation的链接。
后快照。 –
如果没有与UILable一起工作,那么我建议你使用UITextView insted的UILable并设置文本插入像uitextview像 'textView.textContainerInset = UIEdgeInsetsMake(0,0,0,0);' – Vvk