2015-09-28 59 views
1

我已經通過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; 
} 

回答

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; 

} 
+0

你絕對正確 –

+0

@ STONE2如何通過編程獲得的寬度和高度的兄弟... \ –

+0

@KishoreKumar寬度和什麼高度? – Stonz2

相關問題