NSString *const JSPlaybackCellID = @"JSPlaybackCellID";
/**
* 设置老师CollectionView
*/
-(void)setupCollectionView
{
//1.设置布局
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
layout.itemSize = CGSizeMake(CellWidth, CellHeight);
//其中一个44是搜索框高度
layout.sectionInset = UIEdgeInsetsMake(10 + 44, 0, 0, 0);
layout.minimumInteritemSpacing = 0;
layout.minimumLineSpacing = 10;
//2.添加老师视图
UICollectionView *teacherCollectionView = [[UICollectionView alloc]initWithFrame:self.view.frame collectionViewLayout:layout];
teacherCollectionView.dataSource = self;
teacherCollectionView.delegate = self;
teacherCollectionView.backgroundColor = [UIColor clearColor];
teacherCollectionView.backgroundColor = [UIColor whiteColor];
teacherCollectionView.alwaysBounceVertical = YES;
//一个44是学科ScrollView高度
teacherCollectionView.contentInset = UIEdgeInsetsMake(44, 0, 0, 0);
//1.注册cell告诉CollectionView创建怎么样的Cell
//1.通过代码创建
//[teacherCollectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:JSTeacherCollectionViewCellIdentifier];
//2.通过xib创建
UINib *nib = [UINib nibWithNibName:@"JSPlaybackCell" bundle:nil];
[teacherCollectionView registerNib:nib forCellWithReuseIdentifier:JSPlaybackCellID];
self.teacherCollectionView = teacherCollectionView;
[self.view addSubview:teacherCollectionView];
}
以上就是简单的创建 UICollectionView了阿。