Skip to content
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
17 changes: 9 additions & 8 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 All @@ -99,6 +100,6 @@
@protocol TAPageControlDelegate <NSObject>

@optional
- (void)TAPageControl:(TAPageControl *)pageControl didSelectPageAtIndex:(NSInteger)index;
- (void)taPageControl:(TAPageControl *)pageControl didSelectPageAtIndex:(NSInteger)index;

@end
54 changes: 29 additions & 25 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 All @@ -112,8 +113,8 @@ - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
UITouch *touch = [touches anyObject];
if (touch.view != self) {
NSInteger index = [self.dots indexOfObject:touch.view];
if ([self.delegate respondsToSelector:@selector(TAPageControl:didSelectPageAtIndex:)]) {
[self.delegate TAPageControl:self didSelectPageAtIndex:index];
if ([self.delegate respondsToSelector:@selector(taPageControl:didSelectPageAtIndex:)]) {
[self.delegate taPageControl:self didSelectPageAtIndex:index];
}
}
}
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