第一个和第二个UICollectionViewCell的奇怪的上边距

时间:2015-04-22 07:14:54

标签: ios objective-c uicollectionview

我得到了UICollectionView,我的设置:

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    if (collectionView == self.navigationCollectionView)
        return 24;
    else
        return 0;
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    if (collectionView == self.navigationCollectionView)
        return UIEdgeInsetsMake(14.5, 15, 0, 15);
    else // chart collection
        return UIEdgeInsetsMake(0, 0, 0, 0);
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    if (collectionView == self.navigationCollectionView) {
        DashboardModel *dashModel = [self getDashBoardCacheAtIndex:indexPath.row];
        UILabel *label = [[UILabel alloc] init];
        label.text = dashModel.dashboardTitle;
        label.font = [UIFont boldSystemFontOfSize:17];
        [label sizeToFit];
        return CGSizeMake(label.bounds.size.width,self.navigationCollectionView.bounds.size.height);
    }
}

但是在跑步时,它显示如下:

First cell frame is (39,0,85,44) 
Second cell frame is (148,14.5,50,44) 

第一个单元格的顶部插图未正确设置。怎么了?

编辑: 我觉得单元格是由UICollectionView自动居中的。我们可以设置不自动中心吗?

first cell frame is (39,0,85,44) while the second cell frame is (148,14.5,50,44)

0 个答案:

没有答案