#import "RGTypeCollectionViewCell.h"
#define pageNumber 8
@interface FunctionView()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) UICollectionView *myCollectionView;
@property (assign, nonatomic) NSInteger functionHeight;
@property (nonatomic, strong) UIPageControl *pageControl;
@property (nonatomic, strong) NSArray *myData;
@end
static NSString *RGTypeCollectionViewCellID = @"RGTypeCollectionViewCellID";
@implementation FunctionView
-(instancetype)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
[self setupUI];
}
return self;
}
//初始化collectionView
-(void)setupUI{
//
if (nil == _myCollectionView) {
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
flowLayout.minimumLineSpacing = 0;
flowLayout.minimumInteritemSpacing = 0;
flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
_myCollectionView = [[UICollectionView alloc]initWithFrame:self.bounds collectionViewLayout:flowLayout];
_myCollectionView.delegate = self;
_myCollectionView.dataSource = self;
_myCollectionView.pagingEnabled = YES;
_myCollectionView.showsVerticalScrollIndicator = NO;
_myCollectionView.showsHorizontalScrollIndicator = NO;
_myCollectionView.backgroundColor = [UIColor whiteColor];
[_myCollectionView registerClass:[RGTypeCollectionViewCell class] forCellWithReuseIdentifier:RGTypeCollectionViewCellID];
[self addSubview:_myCollectionView];
}
if (nil == _pageControl) {
_pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(0, _myCollectionView.bottom - 20, KScreen_Width, 30)];
_pageControl.currentPage = 0;
_pageControl.currentPageIndicatorTintColor = RGB(88, 148, 178);
_pageControl.pageIndicatorTintColor = RGB(131, 119, 98);
_pageControl.numberOfPages = self.myData.count / pageNumber + ((self.myData.count % pageNumber) > (0) ? 1 : 0);
[self addSubview:_pageControl];
}
}
#pragma mark - UICollectionViewDelegate
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
//计算有多少个, 每行为8个
return (self.myData.count / pageNumber + ((self.myData.count % pageNumber) > (0) ? 1 : 0)) * pageNumber;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
RGTypeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:RGTypeCollectionViewCellID forIndexPath:indexPath];
//小于总数赋值, 大于的时候略过赋空
if (indexPath.item < self.myData.count) {
RGMoreModel *model = self.myData[indexPath.item];
[cell textName:model.name imageName:model.icon];
cell.isShowRed = NO;
}else{
[cell textName:@"" imageName:@""];
cell.isShowRed = NO;
}
return cell;
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
return CGSizeMake(self.width/4, self.height/2);
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.item < self.myData.count) {
//选择某个
if ([self.delegate respondsToSelector:@selector(didSelectIitem:)]) {
RGMoreModel *model = self.myData[indexPath.item];
[self.delegate didSelectIitem:model.vcName];
}
}
}
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
CGFloat offsetX = scrollView.contentOffset.x;
self.pageControl.currentPage = offsetX / KScreen_Width;
}
#pragma mark - setFunctionArr
-(void)setFunctionArr:(NSArray *)functionArr{
_functionArr = functionArr;
self.myCollectionView.height = self.height;
[self.myCollectionView reloadData];
}
-(NSArray *)myData{
if (nil == _myData) {
_myData = [RGMoreModel MyCollectionModelWithData];
}
return _myData;
}
@end
功能页
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- GuidePages(引导页/功能介绍页) 先上图,看一下是否符合你的场景吧! Function Descript...