快上网专注成都网站设计 成都网站制作 成都网站建设
成都网站建设公司服务热线:028-86922220

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

ios中UICollectionView怎么用-创新互联

小编给大家分享一下ios中UICollectionView怎么用,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

网站建设哪家好,找创新互联!专注于网页设计、网站建设、微信开发、小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了高陵免费建站欢迎大家使用!

- (void)viewDidLoad {

  [super viewDidLoad];

  self.title = @"UICollectionView的基本使用";

  self.view.backgroundColor = [UIColor whiteColor];

  UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];

  UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:self.view.bounds collectionViewLayout:layout];

  collectionView.delegate = self;

  collectionView.dataSource = self;

  [collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellID"];

  [self.view addSubview:collectionView];

  // Do any additional setup after loading the view.

}

#pragma mark UICollectionView-delegate and dataSource-UICollectionViewCell的总个数

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

  return 100;

}

#pragma mark UICollectionView-delegate and dataSource 每个UICollectionViewCell

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

  static NSString *cellID = @"cellID";

  UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];

  if(cell == nil){

    cell = [[UICollectionViewCell alloc] init];

  }

  cell.backgroundColor = [UIColor grayColor];

  return cell;

}

#pragma mark -- UICollectionViewDelegate 设置每个 UICollectionView 的大小

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

{

  return CGSizeMake(CGRectGetWidth(self.view.bounds)/3-10, CGRectGetWidth(self.view.bounds)/3-10);

}

#pragma mark - CollectionView section 的个数

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView

{

  return 1;

}

#pragma mark-设置每个UICollectionView 的间距

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{

  return UIEdgeInsetsMake(0, 0, 0,0);

}

#pragma mark-设置每个UICollectionView 的纵向间距

-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{

  return 10;

}

#pragma mark-设置每个UICollectionView 的横向间距

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{

  return 10;

}

#pragma mark-UICollectionView的点击事件

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

  NSLog(@"%@",@(indexPath.row).description);

}

以上是“ios中UICollectionView怎么用”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章题目:ios中UICollectionView怎么用-创新互联
标题网址:http://6mz.cn/article/depiss.html

其他资讯