iOS Uilabel implementation of text adaptive method

Source: Internet
Author: User

Uilabel implementation of Text adaptive method (IOS7)
-(void) inituserinterface{UILabel *label = [[UILabel alloc]init]; Label.numberoflines = 0;    You need to set the number of display lines to unlimited label.font = [Uifont systemfontofsize:15];    Label.textalignment = Nstextalignmentcenter;    Label.text = @ "Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";    Cgsize size = [self sizeWithString:label.text font:label.font];    Label.bounds = CGRectMake (0, 0, size.width, size.height);    Label.center = Self.view.center;    [Self.view Addsubview:label]; }//Definition method facilitates multiple label calls to add code reusability-(cgsize) sizewithstring: (NSString *) string font: (Uifont *) font{cgrect rect = [string bou Ndingrectwithsize:cgsizemake (320, 8000)//limit the maximum width and height options:nsstringdrawingtruncates Lastvisibleline | nsstringdrawingusesfontleading | nsstringdrawinguseslinefragmentorigin//using the line break mode attributes:@{nsfontattributename:font}//        Font Dictionary of descendants Context:nil]; return rect.size;}


iOS Uilabel implementation of text adaptive method

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.