iphone的UIPageControl控件可以显示用户huan'dong滑动到的页码。但是里面的小点的颜色时默认的白色。如果背景也是白色的hu话,你就悲剧了。于是乎上网找了一些资料,找到了改变UIPageControl空间xiao'da小点颜色的方法。解决fang'r方法如下:
GrayPageControl.h:
#import <Foundation/Foundation.h>
@interface GrayPageControl : UIPageControl
{
UIImage* activeImage;
UIImage* inactiveImage;
}
@end
#import "GrayPageControl.h"
@implementation GrayPageControl
//-(id) initWithCoder:(NSCoder *)aDecoder
//{
// self = [super initWithCoder:aDecoder];
//
// activeImage = [[UIImage imageNamed:@"RedPoint.png"] retain];
// inactiveImage = [[UIImage imageNamed:@"BluePoint.png"] retain];
//
// return self;
//}
-(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 = 0; 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 - (96 + 48) / 2, 320.0, 48.0 /2)];
pageControl.userInteractionEnabled = NO;