A new method of IOS7.0 Uilabel to realize adaptive height

Source: Internet
Author: User

//IOS7.0 in Use-(CGRect) Boundingrectwithsize: (cgsize) Size options: (nsstringdrawingoptions) Options attributes: ( Nsdictionary *) Attributes Context: (Nsstringdrawingcontext *) The context method can get the size of the label, from the adaptive height, replacing the previous-(cgsize)    Sizewithfont: (Uifont *) font constrainedtosize: (cgsize) size Linebreakmode: (Nslinebreakmode) Linebreakmode method from Adaptive height //IOS7 method, label adaptive height according to content//set Max Size,width to 200 height max to 999Cgsize maxlabelsize = Cgsizemake ( $,999);    Nsstringdrawingoptions options; Options= Nsstringdrawingtruncateslastvisibleline |Nsstringdrawinguseslinefragmentorigin; //to set the size of a font in a labelNsdictionary *attr = @{nsfontattributename: [Uifont systemfontofsize: -]}; //nodestring is to show the content, in fact, is to measure the size of nodestring on the label aboveCgsize labelsize =[nodestring boundingrectwithsize:maxlabelsize options:options    Attributes:attr context:nil].size; NSLog (@"%s%d labelsize = (%f,%f)", __function__, __line__, Labelsize.width, labelsize.height);

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.