04 --- dynamically change the cell height

Source: Internet
Author: User
Dynamically change cell height

1. Use the return value of the tableview proxy method to determine the cell height of each row

-(Cgfloat) tableview :( uitableview *) tableview heightforrowatindexpath :( nsindexpath *) indexpath

2. uifont

// Returns the Row Height of the font.

* [Uifont systemfontofsize: 10]. lineheight

3. Example of dynamically changing cell height

# Pragma mark-return the cell height of each row-(cgfloat) tableview :( uitableview *) tableview heightforrowatindexpath :( nsindexpath *) indexpath {// 1. retrieve the content of this line of Weibo status * s = _ statuses [indexpath. row]; // 2. calculate the height occupied by Weibo content. nsstring * text = S. text; cgfloat textheight = [text sizewithfont: [uifont systemfontofsize: 15] constrainedtosize: cgsizemake (250, maxfloat) linebreakmode: nslinebreakbywordwrapping]. height; // sizewithfont: Based on words Body to calculate the width and height of the text. // constrainedtosize: the width and height of the calculated text set. The maximum width is 250 pixels. // linebreakmode: line feed mode. // 3. calculate the height of the nickname cgfloat screennameheight = [uifont systemfontofsize: 13]. lineheight; // 4. cell height: height of Weibo content + height of Weibo nickname + height of cgfloat cellheight = screennameheight + textheight + 35; // set the height of Cell Return cellheight <75? 75: cellheight ;}

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.