UICollectionView 分页大小

2019-06-03  本文已影响0人  Luyc_Han
WeChatfd53af9b53d24a87694228afbcf5cf69.png
#import <UIKit/UIKit.h>

@interface PagingEnableLayout : UICollectionViewFlowLayout

@end
#import "PagingEnableLayout.h"
#import <objc/message.h>

#define ScreenWidth [UIScreen mainScreen].bounds.size.width

@implementation PagingEnableLayout

- (void)prepareLayout{
    [super prepareLayout];
    CGFloat contentInset = ScreenWidth-round(300.0*ScreenWidth/375);
    self.collectionView.decelerationRate = UIScrollViewDecelerationRateFast;
    self.collectionView.contentInset = UIEdgeInsetsMake(0, 15, 0, 15);
    if ([self.collectionView respondsToSelector:NSSelectorFromString(@"_setInterpageSpacing:")]) {
        ((void(*)(id,SEL,CGSize))objc_msgSend)(self.collectionView,NSSelectorFromString(@"_setInterpageSpacing:"),CGSizeMake(-(contentInset-self.minimumInteritemSpacing), 0));
    }
    if ([self.collectionView respondsToSelector:NSSelectorFromString(@"_setPagingOrigin:")]) {
        ((void(*)(id,SEL,CGPoint))objc_msgSend)(self.collectionView,NSSelectorFromString(@"_setPagingOrigin:"),CGPointMake(-10, 0));
    }
}

@end
上一篇下一篇

猜你喜欢

热点阅读