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)