300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > storyboard搭建项目_Storyboard 快速搭建UICollectionView

storyboard搭建项目_Storyboard 快速搭建UICollectionView

时间:2019-12-07 11:18:40

相关推荐

storyboard搭建项目_Storyboard 快速搭建UICollectionView

一.在VC里添加CollectionView,在CollectionView中cell直接添加控件,设置约束

1

二.设置好相关代理

2

三.抄写代码

3.1 遵守协议

3.2 自定义cell(不需要xib)

EditPhotoCell.h

EditPhotoCell.m

3.3.实现代理方法

[self.collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([EditPhotoCell class]) bundle:nil] forCellWithReuseIdentifier:NSStringFromClass([EditPhotoCell class])];

记住这里不需要registNib方法来注册cell,因为cell是直接添加到Collection上了,否则会报错

- (NSInteger)collectionView:(UICollectionView*)collectionView numberOfItemsInSection:(NSInteger)section{

return 10;

}

- (CGSize)collectionView:(UICollectionView*)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath*)indexPath{

return CGSizeMake(70, 100);

}

- (nonnull__kindofUICollectionViewCell*)collectionView:(nonnullUICollectionView*)collectionView cellForItemAtIndexPath:(nonnullNSIndexPath*)indexPath {

EditPhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([EditPhotoCell class]) forIndexPath:indexPath];

// cell.model = self.dataSource[indexPath.item];

returncell;

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。