自定义一个pageControl继承于UIpageControl。具体代码如下:
//
// CloPageControl.h
// lvYe
//
// Created by Cloay on 12-8-16.
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface CloPageControl : UIPageControl{
UIImage *activeImage;
UIImage *inActiveIamge;
}
@end
实现方法:
//
// CloPageControl.m
// lvYe
//
// Created by Cloay on 12-8-16.
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import "CloPageControl.h"
@implementation CloPageControl
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
activeImage = [UIImage imageNamed:@"icon_star"];
inActiveIamge = [UIImage imageNamed:@"icon_dot"];
int count = [self.subviews count];
for (int i = 0; i < count; i++) {
UIImageView* dot = [self.subviews objectAtIndex:i];
[dot setFrame:CGRectMake(i*15, 0, 15, 15)];
if (i == 0) {
[dot setImage:activeImage];
}else {
[dot setImage:inActiveIamge];
}
}
}
- (void)setCurrentPage:(NSInteger)currentPage{
[super setCurrentPage:currentPage];
[self updateDots];
}
- (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 = inActiveIamge;
}
}
@end