GMGridView with UIPageControl

I am doing a project and studying using the GMGridView found here: https://github.com/gmoledina/GMGridView .

Has anyone used it and added UIPageControl? If so, how can this be done?

Thanks for the help.

+4
source share
1 answer

You need to make the following changes: -

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, 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; } 

This works with the horizontal layout of the gmgrid view, you can change the logic of the didscroll method to scroll vertically if necessary. It can help you. Happy coding!

+4
source

Source: https://habr.com/ru/post/1442149/


All Articles