Summary of TableView calculation of dynamic row height

Source: Internet
Author: User

Study TableView How to calculate dynamic row height study for two days has not been very likely, today finally made out the desired effect.


First of all, I collected a lot of information on the Internet, the summary of various great gods, and then began to look at, research, testing, the basic ideas are the same.

1. Be sure to set the label's numberofline to 0

2. Size required for text message

3. set the height of the label to Titlesize.height

4. In- (CGFloat) TableView: (UITableView*) TableView Heightforrowatindexpath: (Nsindexpath*) in Indexpath

Return cell initial height plus label increased height.


In the end I used the method is friend told, the idea is the same.


The method used to fetch the label height is

<pre name= "code" class= "OBJC" >[str boundingrectwithsize:size options:nsstringdrawinguseslinefragmentorigin Attributes:@{nsfontattributename:font} context:nil].size


This is a good thing to do. I'm wrapping it up as a method, put it in the category of NSString, and return a desired result as needed to pass in the parameter.

Just write it down.



The article references a lot, write down a few better blog address, perhaps also can use

Dong Platinum Http://www.cnblogs.com/dsxniubility/p/4590474.html

Pengyingh http://www.cnblogs.com/pengyingh/articles/2347700.html


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Summary of TableView calculation of dynamic row 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.