Ios-uilable Multi-line Display text content, automatically calculate text box height based on text length

Source: Internet
Author: User

Iarontalk Blog opens.

The clean and Elegantlife style deduces the deep thought of life.

-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Uilabel as a member of the UIView family, it is widely used, the use of the method is clear and popular enthusiasts like, is the first choice.

The "Multi-line text display" and "AutoFit height to text length" descriptions are used for uilable in the most cut and slightly way.

* * Multi-line display (functional understanding, that is, the completion of input text content, the system automatically according to the width of the text box to do line-wrapping processing) **//

Label.numberoflines = 0;//value is set to 0 o'clock, multiple lines are displayed.

Label.linebreakmode = Uilinebreakmodewordwrap; Wrap Line
  

* * Automatically adjusts the height of the text box based on the length of text (numeric understanding, that is, when "program Monkey Shoes" is concerned with the height of the text box after the self-adaptation.) )**//

NSString *infodetails = @ "The gorgeous parlor arefull of peaceful and elegant breath, the si-mp-le and slight lightmakes t He romantic taste. Life should is so free inward. ";

This method after 7.0, Apple is not recommended to use, but the method is still very useful, of which 320 is the text input limit width, a high degree of freedom to give.

Cgsize size = [infodetails sizewithfont: [Uifont systemfontofsize:16] Constrainedtosize:[cgsizemake (320,2000)]];

If it is necessary to output the height

NSLog (@ "%d", size.height);

For this method to do the following supplementary instructions, both methods from the function above can be completed text boxes according to their contents of the automatic line-wrap display, but the second method text box height changes as the content changes. For example, in the Comments column of the microblog, the content of the comment is different according to the reviewer, so the height of the text display can be automatically controlled by this method, and the height of the Uilabel is not fixed.

  

                                                                       

  

Ios-uilable Multi-line Display text content, automatically calculate text box height based on text length

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.