IOS XIB Cell Adaptive Height implementation

Source: Internet
Author: User

1. Code implementation cell Highly adaptive method

Implemented by code, you need to calculate the height of each control, and then get a cell's

Total height, it is more common to calculate the required height by lable text.

Cgsize labelsize = [@ "asdassdas" sizewithfont:font constrainedtosize:cgsizemake (320,2000 ) Linebreakmode:nslinebreakmodewordwrap];

This allows you to calculate the height of the display, which can be put back in the agent's method within the cell. To be fulfilled today.

is to achieve the desired height through auto layout, which is achieved by using a third-party library (Https://github.com/forkingdog/UITableView-FDTemplateLayoutCell), simplifying the implementation , use this

The library allows you to focus on setting constraints, download and drag the uitableview+fdtemplatelayoutcell.h,uitableview+fdtemplatelayoutcell.m into the project, or you can install through the pod.

2. Achieving results

3. Implementing the Code

-(Nsinteger) Numberofsectionsintableview: (UITableView *) tableview{return 1;}-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{return[Arrdata Count];}-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{Mytableviewcell*cell = [Self.tabview dequeuereusablecellwithidentifier:@"CTF"]; Cell.txt.text=[Arrdata ObjectAtIndex:indexPath.row]; Cell.img.image=[uiimage imagenamed:@"a.jpg"]; returncell;}-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) indexpath{return[TableView Fd_heightforcellwithidentifier:@"CTF"configuration:^ (Mytableviewcell *cell) {Cell.txt.text=[Arrdata ObjectAtIndex:indexPath.row]; Cell.img.image=[uiimage imagenamed:@"a.jpg"]; }];}

Upload more trouble, need to demo can stay in the mailbox, I will send in time.

IOS XIB Cell Adaptive Height implementation

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.