無限輪播 實現原理
阿新 • • 發佈:2019-01-01
1 //
2 // YYViewController.m
3 // 07-無限滾動(迴圈利用)
4 //
5 // Created by apple on 14-8-3.
6 // Copyright (c) 2014年 yangyong. All rights reserved.
7 //
8
9 #import "YYViewController.h"
10 #import "YYimageCell.h"
11
12 #define YYCell @"cell"
13
14 @interface YYViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
15 @property (weak, nonatomic) IBOutlet UICollectionView *collectinView;
16
17 @end
18
19 @implementation YYViewController
20
21 - (void)viewDidLoad
22 {
23 [super viewDidLoad];
24 //註冊cell
25 // static NSString *[email protected]"cell";
26 [self.collectinView registerClass:[YYimageCell class] forCellWithReuseIdentifier:YYCell];
27
28 }
29
30 #pragma mark- UICollectionViewDataSource
31 //一共多少組,預設為1組
32 -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
33 {
34 return 1;
35 }
36 -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
37 {
38 return 16 ;
39 }
40
41 -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
42 {
43 // static NSString *[email protected]"cell";
44 YYimageCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:YYCell forIndexPath:indexPath];
45 cell.backgroundColor=YYRandomColor;
46 NSLog(@"%p,%d",cell,indexPath.item);
47 cell.icon=[NSString stringWithFormat:@"minion_%02d",indexPath.item+1];
48 return cell;
49 }
50
51 #pragma mark-UICollectionViewDelegate
52 @end
2 // YYViewController.m
3 // 07-無限滾動(迴圈利用)
4 //
5 // Created by apple on 14-8-3.
6 // Copyright (c) 2014年 yangyong. All rights reserved.
7 //
8
9 #import "YYViewController.h"
10 #import "YYimageCell.h"
11
12 #define YYCell @"cell"
13
14 @interface YYViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
15
16
17 @end
18
19 @implementation YYViewController
20
21 - (void)viewDidLoad
22 {
23 [super viewDidLoad];
24 //註冊cell
25 // static NSString *[email protected]"cell";
26 [self.collectinView registerClass:[YYimageCell class] forCellWithReuseIdentifier:YYCell];
28 }
29
30 #pragma mark- UICollectionViewDataSource
31 //一共多少組,預設為1組
32 -(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
33 {
34 return 1;
35 }
36 -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
37 {
38 return 16
39 }
40
41 -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
42 {
43 // static NSString *[email protected]"cell";
44 YYimageCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:YYCell forIndexPath:indexPath];
45 cell.backgroundColor=YYRandomColor;
46 NSLog(@"%p,%d",cell,indexPath.item);
47 cell.icon=[NSString stringWithFormat:@"minion_%02d",indexPath.item+1];
48 return cell;
49 }
50
51 #pragma mark-UICollectionViewDelegate
52 @end