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;
}
[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;
}
相关文章推荐
- iOS--UITableView 显示二级菜单
- leetcode_062 Unique Paths
- iOS之UIAlertView的使用
- UIBezierPath精讲
- UITableViewCell的使用介绍
- iOS UITextField的基本用法
- 封装简单的equery
- 有了Auto Layout,为什么你还是害怕写UITabelView的自适应布局?
- 修改UIBarButtonItem字体大小、颜色等相关属性
- 关于在自定义的导航栏中使用UIImagePickerViewControlle
- Number Sequence (KMP算法)
- iOS UILabel 设置行高
- CF_3D_LeastCostBracketSequence
- easyui datagrid 动态生成列
- IOS开发UI篇--使用CAShapeLayer实现复杂的View的遮罩效果
- 自定义导航栏的时候使用UIImagePickerViewControlle Item无法正常显示
- ABAP SAPGUI_PROGRESS_INDICATOR 显示数据处理进度
- UVA 11039(p78)----Building designing
- UESTC 1271(dp动态规划)
- UESTC 1143