UICollectionView的用法

来源:互联网 发布:如何做网络销售技巧 编辑:程序博客网 时间:2024/05/21 14:57

UICollectionView的用法 供以后使用


#import "CoverCollectionViewController.h"#import "CoverCollectionViewCell.h"@interface CoverCollectionViewController () <UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>@property (nonatomic,strong)UICollectionView *collectionView;@end@implementation CoverCollectionViewControllerstatic NSString * const reuseIdentifier = @"Cell";- (void)viewDidLoad {    [super viewDidLoad];        UIImageView *bg = [initUiTools initImageViewWithImageName:@"fish_bg" cornerRadius:0.0f];    [self.view addSubview:bg];    bg.frame = CGRectMake(0, -64, kUIScreenWidth, kUIScreenHeight);        CGFloat itemW = (kUIScreenWidth - 40) / 3;    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];    layout.sectionInset = UIEdgeInsetsMake(5, 10, 5, 10);    layout.itemSize = CGSizeMake(itemW, itemW); // 每一个网格的尺寸    layout.minimumLineSpacing = 10; // 每一行之间的间距    self.collectionView.backgroundColor = [UIColor whiteColor];    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, kUIScreenWidth, kUIScreenHeight - 64) collectionViewLayout:layout];    self.collectionView.delegate = self;    self.collectionView.dataSource = self;    self.collectionView.alwaysBounceVertical = YES;    [self.view addSubview:self.collectionView];    // Register cell classes    [self.collectionView registerClass:[CoverCollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];        }- (void)viewDidAppear:(BOOL)animated{    [super viewDidAppear:animated];    self.view.backgroundColor = [UIColor clearColor];    self.collectionView.backgroundColor = [UIColor clearColor];}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}/*#pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {    // Get the new view controller using [segue destinationViewController].    // Pass the selected object to the new view controller.}*/#pragma mark <UICollectionViewDataSource>- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {    return 1;}- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {    return 30;}- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {    CoverCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];    cell.backgroundColor = [UIColor redColor];            return cell;}


0 0
原创粉丝点击