UILabel adaptive text, making text adaptive and uilabel adaptive

Source: Internet
Author: User

UILabel adaptive text, making text adaptive and uilabel adaptive

// UILabel adaptive text height

UILabel * label = [[UILabel alloc] initWithFrame: CGRectMake (0,100,300,100)];

Label. numberOfLines = 0;

Label. lineBreakMode = NSLineBreakByWordWrapping;

Label. text = @ "we launched a series of special discounts during the 11 S. Please purchase a limited time! Sofa: diamond quality, leader style! Mattress: elegant and elegant, revealing fashion! Distinguished but luxurious, elegant but natural! We create a warm and romantic life together with you! ";

CGSize size = [label sizeThatFits: CGSizeMake (label. frame. size. width, MAXFLOAT)];

Label. frame = CGRectMake (0,100,300, size. height );

Label. font = [UIFont systemFontOfSize: 14];

[Self. view addSubview: label];

 

// If you make the text adaptive

// It is often encountered that the display area in UILabel is fixed, but the text in it shows the appropriate font size, you can use the following method:

UILabel * m_titleLabel = [[UILabel alloc] initWithFrame: CGRectMake (200,350, 40, 30)];

M_titleLabel.backgroundColor = [UIColor clearColor];

M_titleLabel.textColor = [UIColor redColor];

M_titleLabel.font = [UIFont systemFontOfSize: 20];

M_titleLabel.adjustsFontSizeToFitWidth = YES;

M_titleLabel.minimumFontSize = 6; // The default value is 0.

M_titleLabel.text = @ "flying in the sky ";

// When the space is sufficient, the font 20 is used. If the space is insufficient, the font will be automatically adjusted downward, but it will not be less than the font 6, if the font 6 is not complete, the ellipsis (...) will be displayed later...

[Self. view addSubview: m_titleLabel];

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.