因为我一直在使用 UITableView,所以我是使用 UICollectionView 的新手,所以我先道歉。
无论如何,我有一些简单的代码,但由于某些我还不熟悉的原因,一些单元格被放置在屏幕外而不是被移到下一层。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
array = [ [NSMutableArray alloc] initWithObjects:@"Apple", @"Is", @"The", @"Bomb", @".com", @":D", nil];
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
return 5.0;
}
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return array.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
UILabel *label = (UILabel *)[cell viewWithTag:100];
label.text = [array objectAtIndex:indexPath.row];
[cell.layer setBorderWidth:2.0f];
[cell.layer setBorderColor:[UIColor whiteColor].CGColor];
[cell.layer setCornerRadius:10.f];
return cell;
}
带有“Bomb”和“.com”的单元格发生了什么?为什么会截屏?
最佳答案
您需要在 Collection View 上设置 View 约束。查看 Autolayout 编程以设置 UICollectionView 的约束。
关于ios - UICollectionView 单元格与屏幕对齐吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28161127/