Created
March 4, 2017 06:55
-
-
Save bocato/d615b5483ae89add451f91ae062d8e77 to your computer and use it in GitHub Desktop.
Customizing UIPageControl dotImages.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "CustomPageControl.h" | |
@interface CustomPageControl () | |
#pragma mark - View Properties | |
@property (nonatomic,strong) UIImage *selectedImage; | |
@property (nonatomic,strong) UIImage *normalImage; | |
@end | |
@implementation CustomPageControl | |
#pragma mark - View Methods | |
- (void)setCurrentPage:(NSInteger)currentPage { | |
[super setCurrentPage:currentPage]; | |
[self updateDots]; | |
} | |
#pragma mark - Layout Configuration | |
- (void)updateViewForSelectedImage:(UIImage *)selectedImage normalImage:(UIImage *)normalImage { | |
if (!self.selectedImage) { | |
self.selectedImage = selectedImage; | |
} | |
if (!self.normalImage) { | |
self.normalImage = normalImage; | |
} | |
for (int i = 0; i < self.subviews.count; i++){ | |
UIImage *indicatorImage = (i == self.currentPage) ? self.selectedImage : self.normalImage; | |
UIView *indicatorView = self.subviews[i]; | |
indicatorView.frame = CGRectMake(indicatorView.frame.origin.x, indicatorView.frame.origin.y, indicatorImage.size.width, indicatorImage.size.height); | |
indicatorView.backgroundColor = [UIColor colorWithPatternImage:indicatorImage]; | |
if ([indicatorView isKindOfClass:UIImage.class]) { | |
UIImageView *indicatorImageView = (UIImageView *) indicatorView; | |
indicatorImageView.frame = CGRectMake(indicatorView.frame.origin.x, indicatorView.frame.origin.y, indicatorImage.size.width, indicatorImage.size.height); | |
} | |
} | |
} | |
- (void)updateDots { | |
UIImage *selectedImage = [UIImage imageNamed:@"your_active_page_dot_image"]; | |
UIImage *normalImage = [UIImage imageNamed:@"your_inactive_page_dot_image"]; | |
[self updateViewForSelectedImage:selectedImage normalImage:normalImage]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment