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

1) Fixed dot size setup. 2) Add IBInspectable. #6

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions TAPageControl/TAPageControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

@protocol TAPageControlDelegate;


@interface TAPageControl : UIControl


Expand Down Expand Up @@ -39,13 +38,15 @@
/**
* Dot size for dot views. Default is 8 by 8.
*/
@property (nonatomic) CGSize dotSize;

@property (nonatomic) IBInspectable CGSize dotSize;


/**
* Spacing between two dot views. Default is 8.
*/
@property (nonatomic) NSInteger spacingBetweenDots;

@property (nonatomic) IBInspectable NSInteger spacingBetweenDots;


/**
Expand All @@ -62,25 +63,25 @@
/**
* Number of pages for control. Default is 0.
*/
@property (nonatomic) NSInteger numberOfPages;
@property (nonatomic) IBInspectable NSInteger numberOfPages;


/**
* Current page on which control is active. Default is 0.
*/
@property (nonatomic) NSInteger currentPage;
@property (nonatomic) IBInspectable NSInteger currentPage;


/**
* Hide the control if there is only one page. Default is NO.
*/
@property (nonatomic) BOOL hidesForSinglePage;
@property (nonatomic) IBInspectable BOOL hidesForSinglePage;


/**
* Let the control know if should grow bigger by keeping center, or just get longer (right side expanding). By default YES.
*/
@property (nonatomic) BOOL shouldResizeFromCenter;
@property (nonatomic) IBInspectable BOOL shouldResizeFromCenter;


/**
Expand Down
50 changes: 27 additions & 23 deletions TAPageControl/TAPageControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ - (void)initialization
self.currentPage = kDefaultCurrentPage;
self.hidesForSinglePage = kDefaultHideForSinglePage;
self.shouldResizeFromCenter = kDefaultShouldResizeFromCenter;
_dotSize = kDefaultDotSize;
}


Expand Down Expand Up @@ -311,27 +312,44 @@ - (void)setCurrentPage:(NSInteger)currentPage

- (void)setDotImage:(UIImage *)dotImage
{
_dotImage = dotImage;
[self resetDotViews];
self.dotViewClass = nil;
if (_dotImage != dotImage)
{
_dotImage = dotImage;
self.dotSize = _dotImage.size;
[self resetDotViews];
self.dotViewClass = nil;
}
}


- (void)setCurrentDotImage:(UIImage *)currentDotimage
{
_currentDotImage = currentDotimage;
[self resetDotViews];
self.dotViewClass = nil;
if (_currentDotImage != currentDotimage)
{
_currentDotImage = currentDotimage;
[self resetDotViews];
self.dotViewClass = nil;
}
}


- (void)setDotViewClass:(Class)dotViewClass
{
_dotViewClass = dotViewClass;
self.dotSize = CGSizeZero;
[self resetDotViews];
if (_dotViewClass != dotViewClass)
{
_dotViewClass = dotViewClass;
[self resetDotViews];
}
}

- (void)setDotSize:(CGSize)dotSize
{
if (_dotSize.height != dotSize.height || _dotSize.width != dotSize.width)
{
_dotSize = dotSize;
[self resetDotViews];
}
}

#pragma mark - Getters

Expand All @@ -345,18 +363,4 @@ - (NSMutableArray *)dots
return _dots;
}


- (CGSize)dotSize
{
// Dot size logic depending on the source of the dot view
if (self.dotImage && CGSizeEqualToSize(_dotSize, CGSizeZero)) {
_dotSize = self.dotImage.size;
} else if (self.dotViewClass && CGSizeEqualToSize(_dotSize, CGSizeZero)) {
_dotSize = kDefaultDotSize;
return _dotSize;
}

return _dotSize;
}

@end