如何获取UIEdgeInsets实现?
问题描述:
我已经通过storyBoard创建了收藏视图单元格,对于4英寸和5英寸的屏幕,我已经以编程方式设置了UIEdgeInsetsMake,如果设备不是4和5,那么我的故事板UIEdgeInsetsMake必须为此设置。如何获取UIEdgeInsets实现?
怎么办?
这是我的代码
- (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;
}
答
您正在寻找的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;
}
你绝对正确 –
@ STONE2如何通过编程获得的宽度和高度的兄弟... \ –
@KishoreKumar宽度和什么高度? – Stonz2