加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iphone – 带UIPageControl的GMGridView

发布时间:2020-12-14 17:38:16 所属栏目:百科 来源:网络整理
导读:我正在做一个项目,并研究使用这里找到的GMGridView: https://github.com/gmoledina/GMGridView. 有人用它并添加了UIPageControl吗?如果是这样,怎么办呢? 谢谢您的帮助. 解决方法 您需要进行以下更改: – 1.)In Demo1ViewController.h do @interface Demo
我正在做一个项目,并研究使用这里找到的GMGridView: https://github.com/gmoledina/GMGridView.

有人用它并添加了UIPageControl吗?如果是这样,怎么办呢?

谢谢您的帮助.

解决方法

您需要进行以下更改: –

1.)In Demo1ViewController.h  do
    @interface Demo1ViewController : UIViewController
    {
        UIPageControl *pageCont;
    }
    @end

2.)In Demo1ViewController.m  do

In load view method write:-

      pageCont=[[UIPageControl alloc]init];
        pageCont.numberOfPages=10// set this according to your total pages
        pageCont.backgroundColor=[UIColor blueColor];
        [pageCont addTarget:self action:@selector(pagechanged:) forControlEvents:UIControlEventValueChanged];
        pageCont.frame=CGRectMake(0,320,30);// set frame as your requirements
        [self.view addSubview:pageCont]; 
        _gmGridView.delegate=self;

    and add these two methods

    -(IBAction)pagechanged:(id)sender
    {
// add code according  to your requirements if needed

    }

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
        CGFloat pageWidth = _gmGridView.frame.size.width; 
        float fractionalPage = _gmGridView.contentOffset.x / pageWidth;
        NSInteger page = lround(fractionalPage);
        pageCont.currentPage = page; 
    }

这适用于gmgrid视图的水平布局,如果需要,您可以更改didscroll方法的逻辑以进行垂直滚动.它可能会帮助你.快乐的编码!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读