IOS---uitableviewcell adaptive row height (non-AutoLayout)

Source: Internet
Author: User

Title, the program is to use non-AutoLayout write UITableView adaptive Row height, after the author will write a AutoLayout based on the adaptive row height of the small demo.
PS: This applet only applies to children who just touch iOS, only for reference, no technical, big God do not spray.

On the code:

//uitableviewcell#import <UIKit/UIKit.h>  @interface commentarycell : uitableviewcell @property(Retain,nonatomic)UILabel*userid;@property(Retain,nonatomic)UILabel*date;@property(Retain,nonatomic)UILabel*commentary;-(void) SetContent: (NSString*) Userid_dic:(NSString*) Date_dic:(NSString*) Comment_dic;@end#import "commentaryCell.h" floatWidthfloatHeightNSString*COMMENTARYSTR; @implementation Commentarycell @synthesizeUserID;@synthesizeDate@synthesizecommentary;-(ID) Initwithstyle: (Uitableviewcellstyle) style Reuseidentifier: (NSString*) reuseidentifier{ Self= [SuperInitwithstyle:style Reuseidentifier:reuseidentifier];if( Self) { Self. Contentview. BackgroundColor= [UicolorWhitecolor]; [ SelfCreateView]; }return  Self;} -(void) createview{width = Self. Contentview. Frame. Size. Width; Height = Self. Contentview. Frame. Size. Height;//user IDUserID = [[UILabelAlloc] Initwithframe:cgrectmake (width*0.05, height*0.3, width*0.3, height*0.3)]; Userid. Font= [UifontSystemfontofsize: -]; [UserID settextcolor:[UicolorColorwithred:85.0/255.0Green85.0/255.0Blue85.0/255.0Alpha0.6]]; [ Self. ContentviewAddsubview:userid];//Time icon    //Timedate = [[UILabelAlloc] Initwithframe:cgrectmake (width*0.4, height*0.3, width*0.5, height*0.3)]; Date. Font= [UifontSystemfontofsize: -]; [Date settextcolor:[UicolorColorwithred:85.0/255.0Green85.0/255.0Blue85.0/255.0Alpha0.6]]; [ Self. ContentviewAddsubview:date];//ReviewsCommentary = [[UILabelALLOC] init]; [Commentary setnumberoflines:0]; Commentary. Font= [UifontSystemfontofsize: -]; [Commentary settextcolor:[UicolorColorwithred:85.0/255.0Green85.0/255.0Blue85.0/255.0Alpha1]]; [ Self. ContentviewAddsubview:commentary];} -(void) SetContent: (NSString*) Userid_dic:(NSString*) Date_dic:(NSString*) comment_dic{UserID. Text= Userid_dic; Date. Text= Date_dic; [Commentary setnumberoflines:0]; Commentary. Text= Comment_dic; Commentary. Font= [UifontSystemfontofsize: -];cgsizeCommentsize = [ SelfReturnsize:commentary. TextFont:commentary. Font]; [Commentary Setframe:cgrectmake (width*0.05, A, commentsize. Width, commentsize. Height)];}//Returns the size of the label-(cgsize) Returnsize: (NSString*) Text font: (Uifont*) font{floatwidth = [UIScreen mainscreen]. Bounds. Size. Width;floatHeight = [UIScreen mainscreen]. Bounds. Size. Height;cgsize_size = Cgsizemake (width*0.9, height);cgsizeSize = [text Sizewithfont:font constrainedtosize:_size linebreakmode:nslinebreakbywordwrapping];returnSize;}

IOS---uitableviewcell adaptive row height (non-AutoLayout)

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.