I am newbie to iphone programming, I am trying to develop an app which uses page control. My view's background color is white and page controllers default one is also white, which makes page control invisible on my view so I have changed the back ground color of page control to make is visible. Now, the view appears patched and bad. Is there a way to change just the dots color for page control?
Thanks in advance
We customized the UIPageControl to use a custom image for the page indicator, I have listed the guts of the class below...
GrayPageControl.h
@interface GrayPageControl : UIPageControl
{
UIImage* activeImage;
UIImage* inactiveImage;
}
GrayPageControl.m
-(id) initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
activeImage = [[UIImage imageNamed:@"active_page_image.png"] retain];
inactiveImage = [[UIImage imageNamed:@"inactive_page_image.png"] retain];
return self;
}
-(void) updateDots
{
for (int i = 0; i < [self.subviews count]; i++)
{
UIImageView* dot = [self.subviews objectAtIndex:i];
if (i == self.currentPage) dot.image = activeImage;
else dot.image = inactiveImage;
}
}
-(void) setCurrentPage:(NSInteger)page
{
[super setCurrentPage:page];
[self updateDots];
}
Then in the View Controller we just use it like a normal UIPageControl
IBOutlet GrayPageControl* PageIndicator;
Edit:
In the view controller that has the GrayPageControl I have an IBAction that is linked to the GrayPageControl.ValueChanged event.
-(IBAction) pageChanged:(id)sender
{
int page = PageIndicator.currentPage;
// update the scroll view to the appropriate page
CGRect frame = ImagesScroller.frame;
frame.origin.x = frame.size.width * page;
frame.origin.y = 0;
[ImagesScroller scrollRectToVisible:frame animated:YES];
}