Automatic line feed of iOS UILabel, iosuilabel

Source: Internet
Author: User

Automatic line feed of iOS UILabel, iosuilabel

Ideas:

Implementation:

UILabel * label = [[UILabel alloc] init];

Label. text = @ "Hello, this is the test content of UILabel's automatic line feed test. It mainly implements automatic line feed for multi-row data and adaptive data of different rows ";

NSDictionary * attribute =@{ NSFontAttributeName: [UIFont systemFontOfSize: 14]};

CGSize labelSize = [label. text boundingRectWithSize: CGSizeMake (200,500 0) options: Running | NSStringDrawingUsesLineFragmentOrigin | nsstringdrawingusesfontleadattributes: attribute context: nil]. size;

// 200 is the width of UILabel, and 5000 is a preset height, which indicates that

// Note: Previously, sizeWithFont: constrainedToSize: lineBreakMode: Method of the NSString class was used, but this method has been replaced by iOS7 Deprecated, while iOS7 has a new boudingRectWithSize: options: attributes: context: method.

Label. frame = CGRectMake (label. frame. origin. x, label. frame. origin. y, label. frame. size. width, labelSize. height );

// Keep the original Label position and width, but change the height.

Label. numberOfLines = 0; // indicates that the label can be displayed in multiple rows.

Label. textColor = UICOLOR_FROM_RGB (100,100,100, 1 );

Label. font = [UIFont systemFontOfSize: 14];

[Self. view addSubview: label];

 

Related Article

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.