在.h中聲明
創(chuàng)新互聯(lián)專注于企業(yè)成都全網(wǎng)營銷推廣、網(wǎng)站重做改版、石嘴山網(wǎng)站定制設(shè)計、自適應(yīng)品牌網(wǎng)站建設(shè)、H5場景定制、商城建設(shè)、集團公司官網(wǎng)建設(shè)、外貿(mào)營銷網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計等建站業(yè)務(wù),價格優(yōu)惠性價比高,為石嘴山等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。@property (nonatomic, strong) UICollectionView *myCollecionView;
遵循CollectionView協(xié)議
.m文件中實現(xiàn)
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_collectionView.delegate = self;
_collectionView.dataSource = self;
//創(chuàng)建布局對象
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
//itme與item之間的最小間距--默認是10
// flowLayout.minimumInteritemSpacing = 110;
// flowLayout.minimumLineSpacing = 100;
// flowLayout.itemSize = CGSizeMake(80, 80);
// flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
//初始化CollectionView
_myCollecionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 667 - 284, 375, 284) collectionViewLayout:flowLayout];
_myCollecionView.tag = 200;
_myCollecionView.delegate = self;
_myCollecionView.dataSource = self;
_myCollecionView.backgroundColor = [UIColor redColor];
[self.view addSubview:_myCollecionView];
//注冊單元格
[_myCollecionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"myCollecionViewCell"];
}
#pragma mark -UICollectionViewDataSource
//指定組的個數(shù)
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 2;
}
//指定單元格的個數(shù)
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 21;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (collectionView.tag == 100) {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionViewCell" forIndexPath:indexPath];
cell.backgroundColor = [UIColor colorWithRed:arc4random() % 10 * 0.1 green:arc4random() % 10 * 0.1 blue:arc4random() % 10 * 0.1 alpha:1];
return cell;
}else if (collectionView.tag == 200) {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"myCollecionViewCell" forIndexPath:indexPath];
cell.backgroundColor = [UIColor colorWithRed:arc4random() % 10 * 0.1 green:arc4random() % 10 * 0.1 blue:arc4random() % 10 * 0.1 alpha:1];
return cell;
}
return nil;
}
//動態(tài)地設(shè)置單元格的尺寸
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(80, arc4random() % 80);
}
@end
創(chuàng)新互聯(lián)www.cdcxhl.cn,專業(yè)提供香港、美國云服務(wù)器,動態(tài)BGP最優(yōu)骨干路由自動選擇,持續(xù)穩(wěn)定高效的網(wǎng)絡(luò)助力業(yè)務(wù)部署。公司持有工信部辦法的idc、isp許可證, 機房獨有T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確進行流量調(diào)度,確保服務(wù)器高可用性。佳節(jié)活動現(xiàn)已開啟,新人活動云服務(wù)器買多久送多久。