Skip to content

Instantly share code, notes, and snippets.

@a2ikm
Created July 31, 2013 12:00
Show Gist options
  • Save a2ikm/6121382 to your computer and use it in GitHub Desktop.
Save a2ikm/6121382 to your computer and use it in GitHub Desktop.
Customize UIPageControl's image
#import <UIKit/UIKit.h>
@interface MyPageControl : UIPageControl
@end
#import "MyPageControl.h"
@implementation MyPageControl
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
}
return self;
}
- (void)drawRect:(CGRect)rect
{
for (NSInteger i = 0; i < self.numberOfPages; i++) {
UIImageView *pageIcon = [self.subviews objectAtIndex:i];
if ([pageIcon isKindOfClass:[UIImageView class]]) {
if (i == self.currentPage) {
pageIcon.image = [UIImage imageNamed:@"page_on.png"];
} else {
pageIcon.image = [UIImage imageNamed:@"page_off.png"];
}
}
}
}
- (void)setCurrentPage:(NSInteger)curPageIndex
{
[super setCurrentPage:curPageIndex];
[self setNeedsDisplay];
}
@end
@a2ikm
Copy link
Author

a2ikm commented Aug 7, 2013

pageControl.userInteractionEnabled = YESだとタップしたときにデフォルトの画像で描画されてしまう。デフォルトはYES
とはいえinitのなかで設定するのも微妙だし、適宜書き換えが必要。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment