我已经通过storyBoard创建了集合视图单元格,对于4英寸和5英寸屏幕,我已经将UIEdgeInsetsMake设置为编程,如果设备不是4和5,那么我的故事板UIEdgeInsetsMake必须为此设置。
怎么做?
这是我的代码
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout*)collectionViewLayout
insetForSectionAtIndex:(NSInteger)section {
CGRect screenBound = [[UIScreen mainScreen] bounds];
CGSize screenSize = screenBound.size;
CGFloat screenWidth = screenSize.width;
UIEdgeInsets insets= UIEdgeInsetsMake(?,?,?,?);//how to get the current edge insets.
if(screenWidth==320)
{
UIEdgeInsets insets = UIEdgeInsetsMake(0,12,20,2);
return insets;
}
return insets;
}
答案 0 :(得分:1)
您正在寻找contentInset
财产。
此外,您还在代码中重新声明变量insets
。为简单起见,请考虑更改为以下内容:
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout*)collectionViewLayout
insetForSectionAtIndex:(NSInteger)section {
if([UIScreen mainScreen].bounds.size.width == 320)
{
return UIEdgeInsetsMake(0,12,20,2);
}
return collectionView.contentInset;
}