如何在iOS下面显示另外两个标签文本?

时间:2015-10-12 04:35:57

标签: ios objective-c autolayout uilabel

我想在另一个标签下面显示一个标签的文字。尽管文字应该从第一个标签的右边开始。它应该低于另一个标签。请告诉我有可能使用ios吗?

enter image description here

3 个答案:

答案 0 :(得分:1)

在运行时显示,您使用 NSMutableAttributedString 。 例如

 NSDictionary *dicAttributes = @{NSForegroundColorAttributeName:WHITE_COLOR, NSFontAttributeName: UI_DEFAULT_ROBOTO_BOLD(15.0)};
 NSMutableAttributedString *string = [[NSMutableAttributedString alloc]initWithString:@"here is your text which want to set" attributes:dicAttributes]; 

答案 1 :(得分:1)

我得到了你的问题的解决方案。这很容易理解。

NSMutableAttributedString *mutableAttributeStr = [[NSMutableAttributedString alloc]initWithString:@"User this is just a comment.This just a comment.This just a comment."];

NSAttributedString *attributeStr = [[NSAttributedString alloc]initWithString:@"\n" attributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:8]}];

[mutableAttributeStr addAttribute:NSFontAttributeName value: [UIFont fontWithName:@"Helvetica-Bold" size:14.0] range:NSMakeRange(0, 4)];

[mutableAttributeStr appendAttributedString:attributeStr];

labelTextBelowAnotherLabel.numberOfLines = 0;

[labelTextBelowAnotherLabel setAttributedText:mutableAttributeStr];

在编码中,我将helvetica设置为粗体和fontsize以供参考。如果要更改为systemBold,只需更改并根据您的要求设置字体大小。

谢谢 - :)

答案 2 :(得分:0)

是的,这可以在带有故事板的一个标签中。只需使用一个标签并将文本设置为属性。enter image description here

并选择用户词,然后右键单击,您会找到名为" 字体"的选项。现在你可以选择Bold,Italic,UnderLine等。

这是在一个标签中显示文字的简便方法。

对您有所帮助。