【发布时间】:2016-11-18 14:05:39
【问题描述】:
我只想连续显示两个单元格,不管 iPhone 的屏幕尺寸是多少。喜欢,
我的故事板包含一个UICollectionView,由约束连接。
现在,当我在 6、5 秒或更短的时间内运行它时,只有一个单元格出现在一行中。我使用的代码是,
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return [categoryImages count];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
homePageCells *cell = (homePageCells *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cells" forIndexPath:indexPath];
cell.categoryName.text = [categoryNames objectAtIndex:indexPath.row];
return cell;
}
我尝试使用代码以编程方式检测屏幕大小并分配适当的单元格大小,
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
CGSize sizes;
CGSize result = [[UIScreen mainScreen] bounds].size;
NSLog(@"%f",result.height);
if(result.height == 480)
{
//Load 3.5 inch xib
sizes =CGSizeMake(170.f, 170.f);
NSLog(@"3gs");
}
else if(result.height == 568)
{
//Load 4 inch xib
sizes =CGSizeMake(130.f, 130.f);
NSLog(@"5s");
}
else if(result.height == 667.000000)
{
//Load 4.7 inch xib
sizes =CGSizeMake(160.f, 160.f);
NSLog(@"6");
}
else
{
NSLog(@"else");
sizes =CGSizeMake(170.f, 165.f);
}
return sizes;
}
但我也知道这不是正确的方法,所以请给我一个正确的处理方法。
【问题讨论】:
标签: ios storyboard uicollectionview uicollectionviewcell