Code Demo
First, Tabviewcell, the height of the cell is calculated by the ratio of image
#import "TableViewCell.h"@implementationtableviewcell{Uiimageview*ImageView;}- (ID) Initwithstyle: (Uitableviewcellstyle) style Reuseidentifier: (NSString *) reuseidentifier{ Self=[Super Initwithstyle:style Reuseidentifier:reuseidentifier]; if(self) {ImageView=[[Uiimageview alloc] init]; [Self.contentview Addsubview:imageview]; } returnSelf ;}- (void) Setimagename: (NSString *) imageName {_imagename=ImageName; //set the picture that ImageView displaysUIImage *image =[UIImage Imagenamed:imagename]; Imageview.image=image; //set size for ImageView//width is the 1/3 of the screen floatwidth = Cgrectgetwidth ([[UIScreen mainscreen] bounds])/3; //calculate the height according to the proportions floatHeight = image.size.height * Width/Image.size.width; Imageview.frame= CGRectMake (0,0, width, height);}
Second, VC
Create three TableView in VC, three data source array, three CGFloat object record TableView the height change after adding image, each time add picture to the array to give the lowest height (the same height to the first one);
Cellforrow is calculated so that when inserting an array picture, you can also record the height of a number of assembled cells
UIImage *image = [UIImage imagenamed:imagename]; = image; // set size for ImageView // width is the 1/3 of the screen float 3 ; // Calculate the height according to the proportions float height = image.size.height * Width/ image.size.width;
IOS Uitabview Shortcut Waterfall stream