IOS Uitabview Shortcut Waterfall stream

Source: Internet
Author: User

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

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.