Search code examples
iphoneuipagecontrol

How to change Pagecontroller indicator color from default white?


http://apptech.next-munich.com/2010/04/customizing-uipagecontrols-looks.html

In the above url has some sample code for customizing UIPageControl's Looks...

In my application i want to change the pagecontrol indicator(dot) color to some other color instead of default white...I'm following the code that are given in the above link.But,i'm having doubt.

NSString* imgActive = [[NSBundlemainBundle] pathForResource:IMG_PAGE_ACTIVE ofType:nil];

NSString* imgInactive = [[NSBundlemainBundle] pathForResource:IMG_PAGE_INACTIVE ofType:nil];

what should i give for pathForResource:-------------.and where should i add the images for active and inactive pages and how to retrieve the image into application.

please give me some ideas to do this...

Thanks in Advance


Solution

  • Just add the two images to your project resources. For example dot_active.png and dot_inactive.png.

    NSString* imgActive = [[NSBundlemainBundle] pathForResource:@"dot_active" ofType:@"png"];
    NSString* imgInactive = [[NSBundlemainBundle] pathForResource:@"dot_inactive" ofType:@"png"];
    

    I use these two images:

    Active image for the active dot

    Inactive image for the inactive dots

    EDIT

    If you want to modify the size of the dots, maybe

    for (NSUIntegersubviewIndex = 0; subviewIndex < [self.subviews count]; subviewIndex++) {
        UIImageView* subview = [self.subviews objectAtIndex:subviewIndex];
        if (subviewIndex == page) {
            [subview setImage:[UIImage imageWithContentsOfFile:imgActive]];
        } else {
            [subview setImage:[UIImage imageWithContentsOfFile:imgInactive]];
        }
        subview.frame = CGRectMake(/* position and dimensions you need */);
    }
    

    should do the trick.