简体   繁体   中英

How to show two one label text below other in iOS?

I want to show text of one label below the other label.Although text should start from right of first label & it should go below the other label.Please tell me it is possible using ios ?

在此处输入图片说明

At run time display you use NSMutableAttributedString . eg

 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]; 

I got the solution for your question.It is very easy and understandable.

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];

Above in coding i set the helvetica bold and fontsize for reference.If you want to change to systemBold just change and also set the font size according to your requirements.

Thank You-:)

Yes this is possible in One label with storyboard.Just use one label and set text as a Attributed. 在此处输入图片说明

and select User word and just right click and you find option named as a " Font ". now you can select as a Bold,Italic,UnderLine etc.

This is easy way to display text in one Label.

It may be helpful to you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM