iOS development adjusts cell height based on the number of content rows, with label height

Source: Internet
Author: User

Set cell height

-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) Indexpath

{

noticemessage* msg = [Arraynoticemessage objectatindex:indexpath.section];//take out the corresponding section or cell

Uifont *msgfont = [Uifont fontwithname:@ "Arial" size:15];//set font and font size

Define Row Heights

UINT Textlineheight = [@ "The brown fox jumps over the lazy dog" Sizewithfont:msgfont constrainedtosize:cgsizemake (maxfloat , maxfloat)].height;

Set content Height

Cgsize infosize = [msg.strcontent sizewithfont:msgfont constrainedtosize:cgsizemake (MAXFLOAT) LineBreakMode: Uilinebreakmodewordwrap];

return infosize.height;

Set the label height in the following method

-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath

{

static NSString *detailcellidentifier = @ "Valuedetailcell";

static NSString *simplecellidentifier = @ "Valuedetailsimplecell";

NSLog (@ "section%d", indexpath.section);

Information with graphs

noticemessage* msg = [Arraynoticemessage objectAtIndex:indexPath.section];

Detailinfotableviewcell *cell = [TableView dequeuereusablecellwithidentifier:detailcellidentifier];

if (cell = = nil) {

cell = [[Detailinfotableviewcell alloc] Initwithstyle:uitableviewcellstyledefault reuseidentifier:d Etailcellidentifier];

}

Cell.contentView.layer.cornerRadius = 3;

Cell.contentView.layer.masksToBounds = YES;

Cell.contentView.layer.bounds = CGRectMake (0, 0, Cell.contentView.frame.size.width, CELL.CONTENTVIEW.FRAME.SIZE.HEIGHT-50);

Cell.contentView.backgroundColor = [Uicolor colorwithwhite:0.8 alpha:0.3];

Cell.InfoDate.text = msg.strdate;

Cell.InfoTitle.text = Msg.strtitle;

Cell.InfoContent.text = msg.strcontent;

Cell.InfoDate.text = Msg.strtimestamp;

Cell.backgroundcolor = [Uicolor Clearcolor];

Sets the height of the label;

Uifont *msgfont = [Uifont fontwithname:@ "Arial" size:15];

Cgsize infosize = [msg.strcontent sizewithfont:msgfont constrainedtosize:cgsizemake (MAXFLOAT) LineBreakMode: Uilinebreakmodewordwrap];

CGRect frame = cell.InfoContent.frame;

Frame.size.height = Infosize.height;

[Cell.infocontent Setframe:frame];

return cell;

}

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.