Objective C标签行间距?

时间:2017-04-19 14:16:55

标签: objective-c uilabel lines spacing

有没有办法在UILabel内设置两条线的距离? 我尝试在Interface Builder中执行此操作但没有成功。

3 个答案:

答案 0 :(得分:6)

您想要的代码将是这样的:

NSMutableAttributedString* attrString = [[NSMutableAttributedString  alloc] initWithString:@"Sample text"];
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
[style setLineSpacing:24];
[attrString addAttribute:NSParagraphStyleAttributeName
    value:style
    range:NSMakeRange(0, strLength)];
uiLabel.attributedText = attrString;

答案 1 :(得分:4)

您可以使用NSAttributedString在UILabel中的两行之间添加间距:

touchmove

OR

如果您使用的是故事板,则可以通过选择文本类型归属并添加间距值来控制故事板中的行间距:

答案 2 :(得分:0)

从iOS 6开始,Apple将NSAttributedString添加到UIKit,从而可以使用NSParagraphStyle来改变行间距。

或者,您可以使用属性文本通过故事板进行此操作,然后单击...符号。请参阅以下链接以获取屏幕截图。

https://i.stack.imgur.com/aiNfR.png

相关问题