UIPageControl
In most of the time, we want to make application attractive by look wise .UIPagecontroller basically displays a number of pages in small ball representation by default. we can set our own images also . I had used this concept in banner Images that will change in every 2 sec.
There are some steps to follow.
1: allocate the object for UIPagecontroll .
1 2 3 4 5 6 7 8 |
UIPageControl *pager = [[UIPageControl alloc] initWithFrame:CGRectMake(0,totalHeight-120,_mainView.frame.size.width,80)]; //SET a property of UIPageControl pager.backgroundColor = [UIColor clearColor]; pager.numberOfPages = imageCount; //total number of pages. pager.currentPage = 0; pager.highlighted = TRUE; pager.pageIndicatorTintColor = [GlobalData colorWithHexString:@"CCCCCC"]; pager.currentPageIndicatorTintColor = [GlobalData colorWithHexString:GLOBAL_COLOR]; |
2: count the page number in UIScrollView.
1 2 3 4 5 6 7 8 9 |
float width = CGRectGetWidth(_imageScroller.frame); float height = CGRectGetHeight(_imageScroller.frame); float newPosition = _imageScroller.contentOffset.x+width; pagerCounter +=1; if(newPosition == (SCREEN_WIDTH-4) * imageCount) newPosition = 0.0f; CGRect toVisible = CGRectMake(newPosition, 0, width, height); [_imageScroller scrollRectToVisible:toVisible animated:YES]; pager.currentPage = pagerCounter; // here you update the pagenumber. |