MyPageControl.h//创建一个pageControl类
#import "MyPageControl.h"
@implementationMyPageControl
- (id)initWithFrame:(CGRect)frame
{
self= [super initWithFrame:frame];
if(self) {
}
return self;
}
-(void) updateDots
{
for(int i = 0; i < [self.subviews count]; i++)
{
UIImageView* dot = [self imageViewForSubview: [self.subviewsobjectAtIndex:i]];
if(i == self.currentPage)
dot.image= [UIImage imageNamed:@"点1"];
else
dot.image= [UIImage imageNamed:@"点2"];
}
}
- (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;
}
-(void)setCurrentPage:(NSInteger)page
{
[super setCurrentPage:page];
[self updateDots];
}