#import <UIKit/UIKit.h>
@interface LFPageControl : UIPageControl
{
UIImage* activeImage;
UIImage* inactiveImage;
}
@property(nonatomic, retain) UIImage* activeImage;
@property(nonatomic, retain) UIImage* inactiveImage;
@end
#import "LFPageControl.h"
@implementation LFPageControl{
NSInteger lastPage;
}
@synthesize activeImage;
@synthesize inactiveImage;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
activeImage = [UIImage imageNamed:@"active_page_image.png"];
inactiveImage = [UIImage imageNamed:@"inactive_page_image.png"];
lastPage =0;
}
return self;
}
-(id) initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
activeImage = [UIImage imageNamed:@"active_page_image.png"];
inactiveImage = [UIImage imageNamed:@"inactive_page_image.png"];
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 if (lastPage >= i){
dot.image = activeImage;
}else{
dot.image = inactiveImage;
}
}
lastPage = self.currentPage;
}
-(void)setCurrentPage:(NSInteger)page
{
[super setCurrentPage:page];
[self updateDots];
}
@end
Vitor Yudi Hansen