在下面的两种情况下会导致圆点贴图刷新:
1.用户调用setCurrentPage:(NSInteger)currentPage时
所以重载这个函数便可拦截
2.点击圆点矩形区域时
这说明,我们可以通过重载setCurrentPage方法来进行拦截
源码如下:
MyPageControl.h:
#import <Foundation/Foundation.h>
@interface MyPageControl : UIPageControl
{
UIImage* activeImage;
UIImage* inactiveImage;
}
@end
MyPageControl.m:
#import "MyPageControl.h"
@implementation GrayPageControl -(id) initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
activeImage = [[UIImage imageNamed:@"RedPoint.png"] retain];
inactiveImage = [[UIImage imageNamed:@"BluePoint.png"] retain];
return self;
}
-(void) updateDots
{
for (int i = ; i < [self.subviews count]; i++)
{
UIImageView* dot = [self.subviews objectAtIndex:i];
if (i == self.currentPage) dot.image = activeImage;
else dot.image = inactiveImage;
}
}
-(void) setCurrentPage:(NSInteger)page
{
[super setCurrentPage:page];
[self updateDots];
}
@end
调用:
pageControl = [[GrayPageControl alloc] initWithFrame:CGRectMake(0.0, 460.0 - ( + ) / , 320.0, 48.0 /)];
pageControl.userInteractionEnabled = NO;
就是这么简单