简体   繁体   中英

How to write multiple lines in a label

I have a XIB file of type View XIB. In it I have a View controller, and in the View controller I have a label.
I have long text that I want to break, but it doesn't - it gets truncated.
I tried this solution - I did it in the attribute window - but it doesn't help.

您可以使用TextView并禁用IB中的可编辑用户交互启用选项。

use this

myLabel.lineBreakMode = UILineBreakModeWordWrap;

if you are worried about backwards compatibility use this because the comand i mentioned before was introduced in iOS 6.0

myLabel.numberOfLines = 0;

I have been running into a similar problem. I started out with a label, but wanted multi-lines and a UITextView worked great for this, at first. Because I am using a third party library ( MBProgressHUD ) to handle stuff like progress messages and what not, I had thread problems when trying to update a UITextView and show the progress message at the same time.

So I went back to UILabel which actually didn't have thread problems. I found a property to allow a specific number of lines of my choosing, and had to create the label big enough to display those lines. The downfall to this approach is that I don't get the context menus like Copy, Paste, etc. but more importantly I'm not running into thread problems. I can always embed this into a UIScrollView in the future if I so choose.

You could check out my category for UILabel on GitHub. https://gist.github.com/1005520

This lets you resize the height of the label to accommodate the content.

From the Attiribute inspector, choose LineBreaks->Word Wrap option when you have selected the lablel. Also increase the number of lines Label->Lines.

Try Following steps to solve issue :

  • Drag out a UITextView.
  • Double-click it to edit text, place cursor where you want the paragraph break.
  • Option-Enter a couple of times to create a blank line & paragraph.

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