功能页

作者: 飞天蛤蟆 | 来源:发表于2017-07-05 15:18 被阅读0次
#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

相关文章

  • 功能页

  • [65→100] iOS开发02:从启动页看ViewContro

    功能需求 功能完成App都会有一个页面——启动页。启动页最简单的功能就是 显示一张宣传页 几秒钟后消失,跳转其它页...

  • django项目--登陆登出功能

    一、功能需求分析 1、登陆功能分析 1.1、流程 1.2、功能 登陆页面 登陆功能 登出功能 二、登陆页面 1、接...

  • App页面分类

    引导页(欢迎页) 过渡页(启动页) 加载页 沉浸式页面 功能页,eg: 登陆、注册,设置,发布… 列表页 正文页,...

  • 功能调研|启动页和引导页

    一、启动页 每次启动都会出现。 二、引导页 若APP是第一次打开,则在启动页之后出现引导页。

  • 翻页功能

    测试点: 翻页功能常见功能点 1.首页、上一页、下一页、尾页 2.总页数,当前页数 3.指定跳转页 4.指定每页显...

  • 引导页

    引导页设计 一般不会超过5页。作用:让用户了解产品价值和功能,引导用户更快进入使用环境。 按照功能分类: 1.功能...

  • 简单分页插件

    1 功能要求 包含首页、末页、上一页、下一页及页码输入框(风格基于semantic,功能不依赖于框架); 2 Do...

  • 第九天 单页多应用及前端框架JM介绍

    1、单页多应用: 通过异步传输功能实现单页多模块,所谓单页多模块就是在一个地址下可以实现多个功能 2、前端实现可通...

  • 6.1 django项目-新闻博客系统之新闻详情页

    06 新闻详情页 一、功能需求分析 1、功能 新闻详情 评论加载 评论添加 二、新闻详情页 1、接口设计 接口说明...

网友评论

      本文标题:功能页

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