Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to customize the stroke color of the dots #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions SMPageControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ typedef NS_ENUM(NSUInteger, SMPageControlTapBehavior) {
@property (nonatomic, strong) UIImage *pageIndicatorImage UI_APPEARANCE_SELECTOR;
@property (nonatomic, strong) UIImage *pageIndicatorMaskImage UI_APPEARANCE_SELECTOR; // ignored if pageIndicatorImage is set
@property (nonatomic, strong) UIColor *pageIndicatorTintColor UI_APPEARANCE_SELECTOR; // ignored if pageIndicatorImage is set
@property (nonatomic, strong) UIColor *pageIndicatorTintStrokeColor UI_APPEARANCE_SELECTOR; // ignored if pageIndicatorImage is set

@property (nonatomic, strong) UIImage *currentPageIndicatorImage UI_APPEARANCE_SELECTOR;
@property (nonatomic, strong) UIColor *currentPageIndicatorTintColor UI_APPEARANCE_SELECTOR; // ignored if currentPageIndicatorImage is set
@property (nonatomic, strong) UIColor *currentPageIndicatorTintStrokeColor UI_APPEARANCE_SELECTOR; // ignored if currentPageIndicatorImage is set

@property (nonatomic) BOOL hidesForSinglePage; // hide the the indicator if there is only one page. default is NO
@property (nonatomic) BOOL defersCurrentPageDisplay; // if set, clicking to a new page won't update the currently displayed page until -updateCurrentPageDisplay is called. default is NO
Expand Down
11 changes: 10 additions & 1 deletion SMPageControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ - (void)_renderPages:(CGContextRef)context rect:(CGRect)rect
CGFloat xOffset = left;
CGFloat yOffset = 0.0f;
UIColor *fillColor = nil;
UIColor *strokeColor = nil;
UIImage *image = nil;
CGImageRef maskingImage = nil;
CGSize maskSize = CGSizeZero;
Expand All @@ -155,12 +156,14 @@ - (void)_renderPages:(CGContextRef)context rect:(CGRect)rect

if (i == _displayedPage) {
fillColor = _currentPageIndicatorTintColor ? _currentPageIndicatorTintColor : [UIColor whiteColor];
strokeColor = _currentPageIndicatorTintStrokeColor;
image = _currentPageImages[indexNumber];
if (nil == image) {
image = _currentPageIndicatorImage;
}
} else {
fillColor = _pageIndicatorTintColor ? _pageIndicatorTintColor : [[UIColor whiteColor] colorWithAlphaComponent:0.3f];
strokeColor = _pageIndicatorTintStrokeColor;
image = _pageImages[indexNumber];
if (nil == image) {
image = _pageIndicatorImage;
Expand All @@ -180,7 +183,8 @@ - (void)_renderPages:(CGContextRef)context rect:(CGRect)rect
}
}

[fillColor set];
[fillColor setFill];
if (strokeColor) [strokeColor setStroke];
CGRect indicatorRect;
if (image) {
yOffset = [self _topOffsetForHeight:image.size.height rect:rect];
Expand All @@ -197,6 +201,9 @@ - (void)_renderPages:(CGContextRef)context rect:(CGRect)rect
CGFloat centeredXOffset = xOffset + floorf((_measuredIndicatorWidth - _indicatorDiameter) / 2.0f);
indicatorRect = CGRectMake(centeredXOffset, yOffset, _indicatorDiameter, _indicatorDiameter);
CGContextFillEllipseInRect(context, indicatorRect);
if (strokeColor) {
CGContextStrokeEllipseInRect(context, indicatorRect);
}
}

[pageRects addObject:[NSValue valueWithCGRect:indicatorRect]];
Expand Down Expand Up @@ -404,13 +411,15 @@ - (void)setStyleWithDefaults:(SMPageControlStyleDefaults)defaultStyle
self.indicatorDiameter = DEFAULT_INDICATOR_WIDTH_LARGE;
self.indicatorMargin = DEFAULT_INDICATOR_MARGIN_LARGE;
self.pageIndicatorTintColor = [[UIColor whiteColor] colorWithAlphaComponent:0.2f];
self.pageIndicatorTintStrokeColor = nil;
self.minHeight = DEFAULT_MIN_HEIGHT_LARGE;
break;
case SMPageControlDefaultStyleClassic:
default:
self.indicatorDiameter = DEFAULT_INDICATOR_WIDTH;
self.indicatorMargin = DEFAULT_INDICATOR_MARGIN;
self.pageIndicatorTintColor = [[UIColor whiteColor] colorWithAlphaComponent:0.3f];
self.pageIndicatorTintStrokeColor = nil;
self.minHeight = DEFAULT_MIN_HEIGHT;
break;
}
Expand Down