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

    [flowLayout setItemSize:CGSizeMake(SCREENSIZE.width,156)];

    [flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];


    scrollImageView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 94, SCREENSIZE.width,156) collectionViewLayout:flowLayout];

  

    scrollImageView.delegate = self;

    scrollImageView.dataSource = self;


    [scrollImageView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"collection"];

    scrollImageView.showsHorizontalScrollIndicator = NO;

    [self.view addSubview:scrollImageView];


//代理方法

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

{

    return 1;

}


- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView

{

    return 3000;

}


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

{

    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collection" forIndexPath:indexPath];

    int i = (int)indexPath.section%self.imageArray.count;

    UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:self.imageArray[i]]];

    image.frame = CGRectMake(0, 0, SCREENSIZE.width, 156);

    [cell.contentView addSubview:image];

    return cell;

}


转载于:https://my.oschina.net/daniels/blog/549075

Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐