GrayPageControl 在 IOS7 崩溃解决方案

网上开源的GrayPageControl 在ios7下会崩溃,因为ios7修改了UIPageControl内部的实现


stackoverflow 中改出解决方案 注意修改红体字部分



#import "GrayPageControl.h"

@implementation GrayPageControl

-(id) initWithCoder:(NSCoder *)aDecoder

{

    self = [super initWithCoder:aDecoder];

    activeImage = [UIImage imageNamed:@"inactive_page_image"];

    inactiveImage = [UIImage imageNamed:@"active_page_image"];

    [self setCurrentPage:1];

    return self;

}


- (id)initWithFrame:(CGRect)aFrame {

    

if (self = [super initWithFrame:aFrame]) {

        activeImage = [UIImage imageNamed:@"inactive_page_image"];

        inactiveImage = [UIImage imageNamed:@"active_page_image"];

        [self setCurrentPage:1];

}

return self;

}


-(void) updateDots

{

    for (int i = 0; i < [self.subviews count]; i++)

    {

        UIView* dotView = [self.subviews objectAtIndex:i];

        UIImageView* dot = nil;

        

        for (UIView* subview in dotView.subviews)

        {

            if ([subview isKindOfClass:[UIImageView class]])

            {

                dot = (UIImageView*)subview;

                break;

            }

        }

        

        if (dot == nil)

        {

            dot = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, dotView.frame.size.width, dotView.frame.size.height)];

            [dotView addSubview:dot];

        }

        

        if (i == self.currentPage)

        {

            if(activeImage)

                dot.image = activeImage;

        }

        else

        {

            if (inactiveImage)

                dot.image = inactiveImage;

        }

    }

}


-(void) setCurrentPage:(NSInteger)page

{

    [super setCurrentPage:page];

    [self updateDots];

}


具体请参考 http://stackoverflow.com/questions/18975544/uipagecontrol-is-not-with-uiimageview-in-ios7

你可能感兴趣的:(GrayPageControl 在 IOS7 崩溃解决方案)