【代码笔记】自定义布局实现瀑布流
发布时间:2016-03-03 01:00:13
文件目录如下 动画效果图如下: 1 //ViewController文件 2 3 #import "ViewController.h" 4 #import "LYWaterFlowLayout.h" 5 #import &quo ...
文件目录如下
动画效果图如下:
1 //ViewController文件 2 3 #import "ViewController.h" 4 #import "LYWaterFlowLayout.h" 5 #import "LYWaterCell.h" 6 #import "LYShopModel.h" 7 8 @interface ViewController ()<UICollectionViewDataSource> 9 @property(nonatomic,strong)NSArray *shops;10 11 12 @end13 14 @implementation ViewController15 static NSString *ID = @"water";16 17 - (NSArray *)shops{18 19 if (_shops == nil) {20 // 1.读取文件21 NSString *path = [[NSBundle mainBundle ]pathForResource:@"1.plist" ofType:nil];22 NSArray *dictArray = [NSArray arrayWithContentsOfFile:path];23 // 2.字典转模型24 NSMutableArray *tempArray = [NSMutableArray array];25 for (NSDictionary *dict in dictArray) {26 LYShopModel *shop = [LYShopModel shopWithDict:dict];27 [tempArray addObject:shop];28 29 }30 _shops = tempArray;31 32 33 34 }35 return _shops;36 }37 38 - (void)viewDidLoad {39 [super viewDidLoad];40 // Do any additional setup after loading the view, typically from a nib.41 // 0.自定义布局42 LYWaterFlowLayout *waterFlowLayout = [[LYWaterFlowLayout alloc]init];43 // 0.1.传递外界数组到内部44 waterFlowLayout.shops = self.shops;45 46 // 1.创建collectionView47 UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:waterFlowLayout];48 // 2.设置数据源49 collectionView.dataSource = self;50 //// 3.设置代理51 // collectionView.delegate = self;52 53 54 // 3.添加55 [self.view addSubview:collectionView];56 // 4.注册cell57 [collectionView registerNib:[UINib nibWithNibName:@"LYWaterCell" bundle:nil] forCellWithReuseIdentifier:ID];58 59 60 }61 62 - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{63 64 return 1;65 66 }67 68 - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{69 70 return self.shops.count;71 }72 73 - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{74 75 76 // 1.创建cell77 78 LYWaterCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];79 // 2.赋值80 //81 // cell.backgroundColor = [UIColor redColor];82 // 2.1获取模型83 LYShopModel *shop = self.shops[indexPath.item];84 cell.shop = shop;85 86 cell.indexPath=indexPath;87 // 3.返回cell88 return cell;89 90 91 }92 93 @end
原标题:【代码笔记】自定义布局实现瀑布流
关键词:
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。
空运到美国货代:https://www.goluckyvip.com/tag/35212.html
空运到日本fba:https://www.goluckyvip.com/tag/35213.html
空运到新西兰:https://www.goluckyvip.com/tag/35214.html
空运德国专线:https://www.goluckyvip.com/tag/35215.html
空运俄罗斯专线:https://www.goluckyvip.com/tag/35216.html
空运费:https://www.goluckyvip.com/tag/35217.html
探讨内地人开设香港账户的可行性 :https://www.kjdsnews.com/a/1836442.html
在古巴做游轮 古巴旅游项目:https://www.vstour.cn/a/363194.html