美文网首页
UICollectionView 分页大小

UICollectionView 分页大小

作者: Luyc_Han | 来源:发表于2019-06-03 16:22 被阅读0次
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

相关文章

网友评论

      本文标题:UICollectionView 分页大小

      本文链接:https://www.haomeiwen.com/subject/bsocxctx.html