IOS waterfall is implemented through the UICollectionView Control
Some IOS projects use the waterfall stream function. You can choose to use a third-party library or write one by yourself. If you write this function yourself, you can use the UICollectionView Control for display, the settings are divided into several columns.
The Code is as follows:
# Define screenHeight [[UIScreen mainScreen] bounds]. size. height // screen height # define screenWidth [[UIScreen mainScreen] bounds]. size. width // screen width # define colletionCell 3 // set the specific columns @ interface HomeViewController () {UICollectionView * collectionView; NSMutableArray * hArr; // record the height of each cell} @ end @ implementation HomeViewController-(void) viewDidLoad {[super viewDidLoad]; hArr = [[NSMutableArray alloc] init]; optional * flowLayout = [[UICollectionViewFlowLayout alloc] init]; [flowLayout setScrollDirection: direction]; // you can specify horizontal or vertical collectionView = [[UICollectionView alloc] initWithFrame: CGRectMake (0, 0, screenWidth, screenHeight) collectionViewLayout: flowLayout]; collectionView. dataSource = self; collectionView. delegate = self; [collectionView setBackgroundColor: [UIColor clearColor]; [collectionView registerClass: [UICollectionViewCell class] forCellWithReuseIdentifier: @ UICollectionViewCell]; [self. view addSubview: collectionView] ;}# pragma mark -- UICollectionViewDataSource // defines the number of uicollectionviewcells displayed-(NSInteger) collectionView :( UICollectionView *) collectionView numberOfItemsInSection :( NSInteger) section {return 20 ;} // define the number of displayed sections-(NSInteger) numberOfSectionsInCollectionView :( UICollectionView *) collectionView {return 1;} // The content displayed for each UICollectionView-(UICollectionViewCell *) collectionView :( UICollectionView *) collectionView cellForItemAtIndexPath :( NSIndexPath *) indexPath {static NSString * CellIdentifier = @ UICollectionViewCell; UICollectionViewCell * cell = [collectionView progress: CellIdentifier forIndexPath: indexPath]; cell. backgroundColor = [UIColor colorWithRed :( (10 * indexPath. row)/255.0) green :( (20 * indexPath. row)/255.0) blue :( (30 * indexPath. (row)/255.0) alpha: 1.0f]; UILabel * label = [[UILabel alloc] initWithFrame: CGRectMake (0, 0, 20, 20)]; label. textColor = [UIColor redColor]; label. text = [NSString stringWithFormat: @ % d, indexPath. row]; // remove cell for (id subView in cell. contentView. subviews) {[subView removeFromSuperview];} NSInteger remainder = indexPath. row % colletionCell; NSInteger currentRow = indexPath. row/colletionCell; CGFloat currentHeight = [hArr [indexPath. row] floatValue]; CGFloat positonX = (screenWidth/colletionCell-8) * remainder + 5 * (remainder + 1); CGFloat positionY = (currentRow + 1) * 5; for (NSInteger I = 0; I
Implementation result: