Dynamically set the Cell height for ios

Source: Internet
Author: User

Dynamically set the Cell height for ios

-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {

Self. mainTitle = [[UILabel alloc] init];
Self. mainTitle. numberOfLines = 0;
Self. mainTitle. font = [UIFont fontWithName: @ "Hiragino Sans GB" size: 14];
Self. mainTitle. text = cell_info.title;
Self. mainTitle. textColor = [UIColor grayColor];
CGSize titleSize = [self. mainTitle. text boundingRectWithSize: CGSizeMake ([UIScreen mainScreen]. bounds. size. width-20, 0) options: NSStringDrawingUsesLineFragmentOrigin attributes: @ {NSFontAttributeName: self. mainTitle. font} context: nil]. size;
Self. rowHeight = titleSize. height;
Self. mainTitle. frame = CGRectMake (15, 3, titleSize. width, titleSize. height );
[Cell. contentView addSubview: self. mainTitle];

CGRect cellFrame = [cell frame];
CellFrame. origin = CGPointMake (0, 0 );
CellFrame. size. height = self. mainTitle. frame. size. height + 5 + self. imgOne. frame. size. height + 5;
[Cell setFrame: cellFrame];

Return cell;

}

-(CGFloat) tableView :( UITableView *) tableView heightForRowAtIndexPath :( NSIndexPath *) indexPath {
If (indexPath. section = 0 ){
Return 160;
}
Else {
// If (indexPath. row = 0 ){
// UITableViewCell * cell = [self tableView: self. tableView cellForRowAtIndexPath: indexPath];
// Return cell. frame. size. height;
//}
UITableViewCell * cell = [self tableView: self. tableView cellForRowAtIndexPath: indexPath];
Return cell. frame. size. height;
}
}

Related Article

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.