Customize dot with image of UIPageControl at index 0 of UIPageControl

Simply change the UIPageControl page indicator Color with pattern Image self.pageControl.currentPageIndicatorTintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"circle"]];


Try this link:-

Answer with GrayPageControl:- Is there a way to change page indicator dots color

It is really good and reliable.I also have used this code.

You might have to do some more customization as

-(void) updateDots
{
    for (int i = 0; i < [self.subviews count]; i++)
    {
        UIImageView* dot = [self.subviews objectAtIndex:i];

        if (i == self.currentPage) {
            if(i==0) {
                dot.image = [UIImage imageNamed:@"activesearch.png"];
            } else {
                dot.image = activeImage;
            }        
        } else {
            if(i==0) {
                dot.image = [UIImage imageNamed:@"inactivesearch.png"];
            } else {
                dot.image = inactiveImage;
            }
        }
    }
}

I have found a solution for this problem. I know it is not the way but it will work till iOS 8 will be launched in the market.

Reason for Crash:

in iOS 7 [self.subViews objectAtIndex: i] returns UIView Instead of UIImageView and setImage is not the property of UIView and the app crashes. I solve my problem using this following code.

Check Whether the subview is UIView(for iOS7) or UIImageView(for iOS6 or earlier). And If it is UIView I am going to add UIImageView as subview on that view and voila its working and not crash..!!

-(void) updateDots
{
    for (int i = 0; i < [self.subviews count]; i++)
    {
        UIImageView * dot = [self imageViewForSubview:  [self.subviews objectAtIndex: i]];
        if (i == self.currentPage) dot.image = activeImage;
        else dot.image = inactiveImage;
    }
}
- (UIImageView *) imageViewForSubview: (UIView *) view
{
    UIImageView * dot = nil;
    if ([view isKindOfClass: [UIView class]])
    {
        for (UIView* subview in view.subviews)
        {
            if ([subview isKindOfClass:[UIImageView class]])
            {
                dot = (UIImageView *)subview;
                break;
            }
        }
        if (dot == nil)
        {
            dot = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, view.frame.size.width, view.frame.size.height)];
            [view addSubview:dot];
        }
    }
    else
    {
        dot = (UIImageView *) view;
    }

    return dot;
}

Also, to clear the images that are already there, set the tint colors for the existing indicators to transparent:

- (void)awakeFromNib
{   
    self.pageIndicatorTintColor = [UIColor clearColor];
    self.currentPageIndicatorTintColor = [UIColor clearColor];
}

Hope this will solve ur issue for iOS 7.

Happy coding

Tags:

Ios

Iphone