網上開源的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