iphone – 带UIPageControl的GMGridView

前端之家收集整理的这篇文章主要介绍了iphone – 带UIPageControl的GMGridView前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在做一个项目,并研究使用这里找到的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方法的逻辑以进行垂直滚动.它可能会帮助你.快乐的编码!

猜你在找的Xcode相关文章