IOS 瀑布流
来源:互联网 发布:什么是软件嵌入式培养 编辑:程序博客网 时间:2024/06/12 00:17
CHTCollectionViewWaterfallLayout下载链接
layout = [[CHTCollectionViewWaterfallLayout alloc] init]; layout.sectionInset = UIEdgeInsetsMake(0, 5, 5, 5); layout.columnCount = 2; layout.minimumInteritemSpacing = 5; layout.minimumColumnSpacing = 5; self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight-64-10) collectionViewLayout:layout]; self.collectionView.delegate = self; self.collectionView.dataSource = self; self.collectionView.backgroundColor = [UIColor whiteColor]; [self.collectionView registerNib:[UINib nibWithNibName:@"WaterViewCell" bundle:nil] forCellWithReuseIdentifier:@"WaterViewCell"]; [_collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:CHTCollectionElementKindSectionHeader withReuseIdentifier:MYHeader];//保持一直可滑动 self.collectionView.alwaysBounceVertical = YES; [self.view addSubview:self.collectionView];
#pragma mark - UICollectionView Delegate//获取每组返回几个数据- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return _dataArr.count; }//获取返回几组- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{ return 1;}//- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { WaterViewCell *cell = (WaterViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"WaterViewCell" forIndexPath:indexPath]; if (indexPath.row<_dataArr.count) { WaterModel *model = [_dataArr objectAtIndex:indexPath.row]; cell.model = model; //设置图片的高度 [cell.imageView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:[UIImage imageNamed:@"ls_AdDefaultImage.png"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { if (image) { //宽高比 CGFloat x = image.size.width/image.size.height; CGFloat cellHeight = ((screenWidth-30)/2)/x; if (cell.model.imageSize.height!=cellHeight) { model.imageSize = CGSizeMake((screenWidth-30)/2, cellHeight); //刷新时不让屏幕闪光 [UIView performWithoutAnimation:^{ [_collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]]; }]; } } }]; } return cell; }#pragma mark - CHTCollectionViewDelegateWaterfallLayout- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row<_dataArr.count) { WaterModel *model = [_dataArr objectAtIndex:indexPath.row]; if (model.imageSize.height!=0) { return model.imageSize; } return CGSizeMake((screenWidth-30)/2, 0); } return CGSizeZero; }
阅读全文
0 0
- ios瀑布流心得
- iOS 瀑布流
- ios瀑布流心得
- ios瀑布流心得
- iOS 瀑布流实现
- ios 瀑布流
- iOS瀑布流
- iOS UICollectionView瀑布流
- ios瀑布流
- iOS瀑布流
- iOS 不规则瀑布流
- iOS瀑布流Demo
- iOS 瀑布流总结
- ios . 瀑布流
- IOS 瀑布流
- iOS瀑布流
- iOS 实现瀑布流界面
- iOS 实现 瀑布流界面
- 静态数据成员与非静态数据成员的区别
- 今年生男孩取什么名好的超简单起名方法
- TP5自带分页部分代码
- java简单的定时器实现
- Yii框架 AR 增删改查
- IOS 瀑布流
- cocos2d ios触摸事件分发
- Xlib.h No such file or directory 问题解决
- three.js 02-02 之使用几何与网格对象
- CentOS 6&&7进入救援模式的方法
- 万事开头难
- tcp的三次握手
- 浏览器 发展历史
- docker使用mysql时的端口映射问题