#import "ViewController.h"
#import "CollectionViewCell.h"
// 主屏的宽度
#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
// 主屏的高度
#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
@interface ViewController ()
@property (nonatomic , strong) UICollectionView *collectionView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//背景颜色
self.view.backgroundColor = [UIColor whiteColor];
//导航条颜色
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:251/255.0 green:183/255.0 blue:40/255.0 alpha:1];
//导航标题
UILabel*navLab = [[UILabelalloc]initWithFrame:CGRectMake((SCREEN_WIDTH-60)/2,10,60,30)];
navLab.text=@"采煤机专项闯关";
navLab.textColor= [UIColorwhiteColor];
navLab.font= [UIFontsystemFontOfSize:18];
self.navigationItem.titleView = navLab;
//网格布局 网格创建
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
[flowLayoutsetScrollDirection:UICollectionViewScrollDirectionVertical];
//间距
flowLayout.minimumLineSpacing=32;
flowLayout.minimumInteritemSpacing = 42;
//设置CollectionView的属性
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(26, 86, SCREEN_WIDTH-26*2, SCREEN_HEIGHT-22) collectionViewLayout:flowLayout];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
//背景颜色为红色
self.collectionView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.collectionView];
//注册Cell
[self.collectionView registerNib:[UINib nibWithNibName:@"CollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"cell"];
}
#pragma mark 设置CollectionView每组所包含的个数
- (NSInteger)collectionView:(UICollectionView*)collectionView numberOfItemsInSection:(NSInteger)section
{
return 16;
}
#pragma mark 设置CollectionCell的内容
- (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(NSIndexPath*)indexPath
{
staticNSString*identify =@"cell";
CollectionViewCell*cell = [collectionViewdequeueReusableCellWithReuseIdentifier:identifyforIndexPath:indexPath];
cell.backgroundColor= [UIColorwhiteColor];
returncell;
}
//每个单元格的大小size
- (CGSize)collectionView:(UICollectionView*)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath*)indexPath
{
return CGSizeMake(49 ,69);
}