在下面的两种情况下会导致圆点贴图刷新:
1.用户调用setCurrentPage:(NSInteger)currentPage时
所以重载这个函数便可拦截
2.点击圆点矩形区域时
这说明,我们可以通过重载setCurrentPage方法来进行拦截
源码如下:
1 MyPageControl.h: 2 #import <Foundation/Foundation.h> 3 @interface MyPageControl : UIPageControl 4 { 5 UIImage* activeImage; 6 UIImage* inactiveImage; 7 } 8 @end
1 MyPageControl.m: 2 #import "MyPageControl.h" 3 @implementation GrayPageControl 4 5 -(id) initWithFrame:(CGRect)frame 6 { 7 self = [super initWithFrame:frame]; 8 activeImage = [[UIImage imageNamed:@"RedPoint.png"] retain]; 9 inactiveImage = [[UIImage imageNamed:@"BluePoint.png"] retain]; 10 return self; 11 } 12 -(void) updateDots 13 { 14 for (int i = 0; i < [self.subviews count]; i++) 15 { 16 UIImageView* dot = [self.subviews objectAtIndex:i]; 17 if (i == self.currentPage) dot.image = activeImage; 18 else dot.image = inactiveImage; 19 } 20 } 21 -(void) setCurrentPage:(NSInteger)page 22 { 23 [super setCurrentPage:page]; 24 [self updateDots]; 25 } 26 @end
调用:
pageControl = [[GrayPageControl alloc] initWithFrame:CGRectMake(0.0, 460.0 - (96 + 48) / 2, 320.0, 48.0 /2)]; pageControl.userInteractionEnabled = NO;
就是这么简单
本文转自编程小翁博客园博客,原文链接:http://www.cnblogs.com/wengzilin/p/3210331.html,如需转载请自行联系原作者