iOS 之UICollectionView 使用

来源:互联网 发布:mac vi编辑器保存退出 编辑:程序博客网 时间:2024/05/16 12:20
同样需要一个重用的ID:

NSString *const JSPlaybackCellID =@"JSPlaybackCellID";

/**

 *  设置老师CollectionView

 */

-(void)setupCollectionView

{

   //1.设置布局

   UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayoutalloc]init];

    layout.itemSize =CGSizeMake(CellWidth,CellHeight);

    //其中一个44是搜索框高度

    layout.sectionInset =UIEdgeInsetsMake(10 +44, 0,0, 0);

    layout.minimumInteritemSpacing =0;

    layout.minimumLineSpacing =10;

    

    //2.添加老师视图

   UICollectionView *teacherCollectionView = [[UICollectionViewalloc]initWithFrame:self.view.framecollectionViewLayout:layout];

    teacherCollectionView.dataSource =self;

    teacherCollectionView.delegate =self;

    teacherCollectionView.backgroundColor = [UIColorclearColor];

    teacherCollectionView.backgroundColor = [UIColorwhiteColor];

    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 = [UINibnibWithNibName:@"JSPlaybackCell"bundle:nil];

    [teacherCollectionViewregisterNib:nib forCellWithReuseIdentifier:JSPlaybackCellID];

    

    self.teacherCollectionView = teacherCollectionView;

    

    [self.viewaddSubview:teacherCollectionView];

}

以上就是简单的创建 UICollectionView了阿。
0 0
原创粉丝点击