没有注册这个 设置区头高度 -(CGSize)collectionView:(UICollectionView )collectionView layout:(UICollectionViewLayout...:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)**collectionViewLayout sizeForItemAtIndexPath...上的数据都是取自于它所以,此处应该把数据源也随着移动更新下 - (void)collectionView:(UICollectionView *)collectionView moveItemAtIndexPath...]; break; } } ---- //设置元素大小 -(CGSize)collectionView:(UICollectionView *)collectionView layout...:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{ return
:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath...{ return 1; } -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection...:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath...:(NSInteger)section; 动态设置每列的间距大小 - (CGFloat)collectionView:(UICollectionView *)collectionView layout:...:(NSInteger)section; 动态设置某个分区尾视图大小 - (CGSize)collectionView:(UICollectionView *)collectionView layout
=self; self.collectionView.delegate=self; [self.collectionView setBackgroundColor:[UIColor clearColor...//定义展示的UICollectionViewCell的个数 -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection...{ return 2; } //每个UICollectionView展示的内容 -(UICollectionViewCell )collectionView:(UICollectionView )...collectionView cellForItemAtIndexPath:(NSIndexPath )indexPath { static NSString CellIdentifier = @...:(UICollectionView )collectionView layout:(UICollectionViewLayout)collectionViewLayout sizeForItemAtIndexPath
*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath;...- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath...:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath...:(NSIndexPath *)indexPath; - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(...:(NSInteger)section; - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout
= self; self.collectionView.delegate=self; [self.collectionView registerClass:[UICollectionViewCell...)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout...sizeForItemAtIndexPath:(NSIndexPath *)indexPath{ return CGSizeMake(arc4random()%100+50, 100); }...)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{ return...10; } -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath
通过设定itemSize可以全局地改变所有cell的尺寸,如果想要对某个cell制定尺寸, //可以使用-collectionView:layout:sizeForItemAtIndexPath:方法。...:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath...:(NSIndexPath *)indexPath; // 设定collectionView(指定区)的边距 - (UIEdgeInsets)collectionView:(UICollectionView...// 当指定indexPath处的item被选择时触发 - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath...*)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath - (void)collectionView:(UICollectionView
indexPath位置cell对应的布局属性*/ - (CGRect)itemFrameOfHorizontalGridWaterFlow:(NSIndexPath *)indexPath{ //collectionView...的高度 CGFloat collectionH = self.collectionView.frame.size.height; //设置布局属性item的frame CGFloat...h = [self.delegate waterFlowLayout:self sizeForItemAtIndexPath:indexPath].height; CGFloat w = [self.delegate...waterFlowLayout:self sizeForItemAtIndexPath:indexPath].width; CGFloat x = 0; CGFloat y
=[UIColor whiteColor]; collectionView.delegate=self; collectionView.dataSource=self; [self.view...的个数 -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section...{ return 1; } //每一个UICollectionView展示的内容 -(UICollectionViewCell *)collectionView:(UICollectionView...*)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell * cell = [collectionView...:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath
= 100+i; collectionView.dataSource = self; collectionView.delegate = self; collectionView.alwaysBounceHorizontal...= NO; collectionView.alwaysBounceVertical = YES; collectionView.backgroundColor = [UIColor...= NO; collectionView.scrollEnabled = NO; collectionView.backgroundColor = [UIColor blueColor...]; } CollectionView的代理: #pragma mark - UICollectionDataSource - (CGSize)collectionView:(UICollectionView...*)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath
,基本上就可以保证CollectionView工作正常了。...• -collectionView: didHighlightItemAtIndexPath: 如果1回答为是,那么高亮 • -collectionView: shouldSelectItemAtIndexPath...通过设定itemSize可以全局地改变所有cell的尺寸,如果想要对某个cell制定尺寸,可以使用-collectionView: layout: sizeForItemAtIndexPath:方法。...、设置sizeForItemAtIndexPath; //定义每个UICollectionViewCell 的大小 - (CGSize) collectionView: (UICollectionView...*)collectionView layout: (UICollectionViewLayout*) collectionViewLayout sizeForItemAtIndexPath: (NSIndexPath
= false; self.collectionView.showsVerticalScrollIndicator = false; self.collectionView.backgroundColor...= false; self.collectionView.showsVerticalScrollIndicator = false; self.collectionView.scrollEnabled...= flowLayout; self.collectionView.dataSource = self; self.collectionView.delegate = self; 代理方法 Swift...:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath...(collectionView: UICollectionView) -> Int { return 1; } func collectionView(collectionView:
= [UIColor whiteColor]; _collectionView.showsVerticalScrollIndicator = NO; _collectionView.bounces...= NO; _collectionView.dataSource = self; _collectionView.delegate = self;...{ return 1; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection...*)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath...)); return size; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
(10_0); @optional // 取消提前加载数据 - (void)collectionView:(UICollectionView *)collectionView cancelPrefetchingForItemsAtIndexPaths...运行环境:Xcode 8.2.1 + iOS 10.2 核心步骤: 1、遵从 UICollectionViewDataSourcePrefetching 协议 2、实现 collectionView...:prefetchItemsAtIndexPaths 方法和collectionView:cancelPrefetchItemsAtIndexPaths 方法(可选) 3、将第1步中遵从协议的类设置为...; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath...:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath
collectionView.showsHorizontalScrollIndicator = NO; collectionView.showsVerticalScrollIndicator...= NO; collectionView.alwaysBounceVertical = YES; [self.view addSubview:collectionView];...= collectionView; //注册cell [self.collectionView registerClass:[MovieCollectionViewCell...375 * (value)) ) //collectionView delegate A2DynamicDelegate *delegate = self.collectionView.bk_dynamicDelegate...; //item Size [delegate implementMethod:@selector(collectionView:layout:sizeForItemAtIndexPath
{ } 复制代码 //每一节有几个单元格 - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection...*)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind...-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath...*)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath...:(NSInteger)section{ } 复制代码 //动态设置某个分区尾视图大小 - (CGSize)collectionView:(UICollectionView *)collectionView
= self; collectionView.dataSource = self; [self.view addSubview:collectionView]; } 既然我们将delegate...{ return 1; } // section内行数 - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection...:(NSInteger)section { return 10; } // 每个cell的尺寸 - (CGSize)collectionView:(UICollectionView *)collectionView...layout:(nonnull UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(nonnull NSIndexPath...:(NSInteger)section { return 4; } // 水平间距 - (CGFloat)collectionView:(UICollectionView *)collectionView
值得一提的是collectionview只能采用重用的方式来加载cell。...- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(...3.设置每一个item的size #pragma mark - item的size -(CGSize)collectionView:(UICollectionView *)collectionView...layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath...:self.collectionView layout:self sizeForItemAtIndexPath:indexPath]; //然后比较列数组中的列的高度,找出最小高度的列 float
*)collectionView layout: (UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath...Objective-C /** * Section中每个Cell的上下边距 */ - (CGFloat)collectionView: (UICollectionView *)collectionView...Objective-C /** * Section中每个Cell的左右边距 */ - (CGFloat)collectionView: (UICollectionView *)collectionView...Objective-C /** * headerView的大小 */ - (CGSize)collectionView: (UICollectionView *)collectionView...Objective-C /** * Cell多选时是否支持取消功能 */ - (BOOL)collectionView:(UICollectionView *)collectionView
7 sizeForItemAtIndexPath: (NSIndexPath *)indexPath{ 8 9 if (indexPath.section == 0) {...1 /** 2 * Section中每个Cell的上下边距 3 */ 4 - (CGFloat)collectionView: (UICollectionView *)collectionView...1 /** 2 * Section中每个Cell的左右边距 3 */ 4 - (CGFloat)collectionView: (UICollectionView *)collectionView...1 /** 2 * headerView的大小 3 */ 4 - (CGSize)collectionView: (UICollectionView *)collectionView 5...1 /** 2 * 如果Cell可以高亮,Cell变为高亮后调用该方法 3 */ 4 - (void)collectionView: (UICollectionView *)collectionView
indexPath; //返回内容高度 -(CGSize)collectionViewContentSize; 用法:注意遵循WSLWaterFlowLayoutDelegate协议,代理方法和TableView、collectionView...itemHeight; /** 竖向瀑布流 item等高不等宽 列数、行数无用 */ - (CGSize)waterFlowLayout:(WSLWaterFlowLayout *)waterFlowLayout sizeForItemAtIndexPath
领取专属 10元无门槛券
手把手带您无忧上云