您的位置:首页 > 产品设计 > UI/UE

UICollectionView

2016-03-23 23:01 330 查看
- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

CGFloat itemWidth = (self.view.bounds.size.width - margin*3) / 2;

CGFloat itemHeight = itemWidth * 0.85 + 100;

UICollectionViewFlowLayout*layout = [[UICollectionViewFlowLayout alloc]init];

layout.itemSize = CGSizeMake(itemWidth, itemHeight);

layout.minimumInteritemSpacing = margin;

layout.minimumLineSpacing = margin;

layout.sectionInset = UIEdgeInsetsMake(margin, margin, margin, margin);

self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) collectionViewLayout:layout];

[self.view addSubview:self.collectionView];

self.collectionView.dataSource = self;

self.collectionView.delegate = self;

self.collectionView.backgroundColor = [UIColor whiteColor];

[self.collectionView registerClass:[HomeCell class] forCellWithReuseIdentifier:HYSquareHotViewCellIdentifier];

}

#pragma mark Delegate & DataSource

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView

{

return 1;

}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section

{

return 10;

}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

{

HomeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:HYSquareHotViewCellIdentifier forIndexPath:indexPath];

cell.backgroundColor = [UIColor colorWithRed:((10 * indexPath.row) / 255.0) green:((20 * indexPath.row)/255.0) blue:((30 * indexPath.row)/255.0) alpha:1.0f];

return cell;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: