您的位置:首页 > 产品设计 > UI/UE

UIPageControl自定义点的颜色

2011-11-20 13:19 232 查看


UIPageControl自定义点的颜色









首先导入已经封装好的两个文件GrayPageControl.h,GrayPageControl.m,里面继承了UIPageControl,重写了他的方法。文件内容如下:

GrayPageControl.h:

#import <Foundation/Foundation.h>

@interface GrayPageControl : UIPageControl {

UIImage* activeImage;

UIImage* inactiveImage;

}

@end

GrayPageControl.m:

#import “GrayPageControl.h”

@implementation GrayPageControl

-(id) initWithCoder:(NSCoder *)aDecoder

{

self = [super initWithCoder:aDecoder];

activeImage = [[UIImage imageNamed:@"inactive_page_image.png"] retain];

inactiveImage = [[UIImage imageNamed:@"active_page_image.png"] retain];

[self setCurrentPage:1];

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];

}

-(void)dealloc

{

[super dealloc];

}

@end

在主程序中,只要程序把GrayPageControl的对象当做UIPageControl的对象做就可以了,另外注意,关联控件的时候

要继承GrayPageControl类
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: