【问题标题】:How to get the curent UIEdgeInsetsMake?如何获取当前的 UIEdgeInsetsMake?
【发布时间】:2015-12-25 18:19:38
【问题描述】:

我已经通过故事板创建了集合视图单元格,对于 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;
}

【问题讨论】:

    标签: ios objective-c ios7 uicollectionviewcell uiedgeinsets


    【解决方案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;
    
    }
    

    【讨论】:

    • @Stone2 如何通过编程方式获取宽度和高度...\
    • @KishoreKumar 宽度和高度是什么?
    猜你喜欢
    • 2019-04-22
    • 2011-03-01
    • 2014-09-27
    • 2011-06-26
    • 1970-01-01
    • 2014-01-27
    • 1970-01-01
    • 2018-03-31
    • 2021-08-02
    相关资源
    最近更新 更多