我有一个视图控制器,其中包含具有以下设置的集合视图:
- (void)viewDidLoad {
[super viewDidLoad];
[self createDataSource]; //this one contains 6 UIColor objects used for the collection view cells
UINib *cellNib = [UINib nibWithNibName:@"CustomCollectionViewCell" bundle:nil];
[self.collectionView registerNib:cellNib forCellWithReuseIdentifier:@"customCollectionViewCellIdentifier"];
}
UICollectionViewDataSource方法如下所示:
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 6;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CustomCollectionViewCell *customCollectionViewCell = (CustomCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"customCollectionViewCellIdentifier" forIndexPath:indexPath];
UIColor *color = self.dataSource[indexPath.item];
customCollectionViewCell.childView.backgroundColor = color;
return customCollectionViewCell;
}
UICollectionViewDelegateFlowLayout方法如下所示:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
CGSize cellSize = CGSizeMake(self.collectionView.frame.size.width / 2, self.collectionView.frame.size.height / 3);
return cellSize;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsZero;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
return 0;
}
话虽如此,iPhone X上的结果似乎与iPhone 6S Plus上的结果不同。
如何在iPhone X上获得相同的结果?
谢谢!