Skip to content

Commit

Permalink
Added minHeight option to allow configuration of the height of the co…
Browse files Browse the repository at this point in the history
…ntrol. If set to less than the indicatorDiameter, the value will be set to the indicatorDiameter.
  • Loading branch information
idpaterson committed Oct 24, 2013
1 parent 84e2588 commit f4fa3bc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions SMPageControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ typedef NS_ENUM(NSUInteger, SMPageControlTapBehavior) {
@property (nonatomic) NSInteger currentPage;
@property (nonatomic) CGFloat indicatorMargin UI_APPEARANCE_SELECTOR; // deafult is 10
@property (nonatomic) CGFloat indicatorDiameter UI_APPEARANCE_SELECTOR; // deafult is 6
@property (nonatomic) CGFloat minHeight UI_APPEARANCE_SELECTOR; // default is 36, cannot be less than indicatorDiameter
@property (nonatomic) SMPageControlAlignment alignment UI_APPEARANCE_SELECTOR; // deafult is Center
@property (nonatomic) SMPageControlVerticalAlignment verticalAlignment UI_APPEARANCE_SELECTOR; // deafult is Middle

Expand Down
22 changes: 18 additions & 4 deletions SMPageControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#define DEFAULT_INDICATOR_WIDTH_LARGE 7.0f
#define DEFAULT_INDICATOR_MARGIN_LARGE 9.0f

#define MIN_HEIGHT 36.0f

typedef NS_ENUM(NSUInteger, SMPageControlImageType) {
SMPageControlImageTypeNormal = 1,
SMPageControlImageTypeCurrent,
Expand Down Expand Up @@ -78,6 +76,7 @@ - (void)_initialize
{
_numberOfPages = 0;
_tapBehavior = SMPageControlTapBehaviorStep;
_minHeight = 36.0f;

self.backgroundColor = [UIColor clearColor];

Expand Down Expand Up @@ -370,13 +369,13 @@ - (UIImage *)imageMaskForPage:(NSInteger)pageIndex
- (CGSize)sizeThatFits:(CGSize)size
{
CGSize sizeThatFits = [self sizeForNumberOfPages:self.numberOfPages];
sizeThatFits.height = MAX(sizeThatFits.height, MIN_HEIGHT);
sizeThatFits.height = MAX(sizeThatFits.height, _minHeight);
return sizeThatFits;
}

- (CGSize)intrinsicContentSize
{
CGSize intrinsicContentSize = CGSizeMake(UIViewNoIntrinsicMetric, MAX(_measuredIndicatorHeight, MIN_HEIGHT));
CGSize intrinsicContentSize = CGSizeMake(UIViewNoIntrinsicMetric, MAX(_measuredIndicatorHeight, _minHeight));
return intrinsicContentSize;
}

Expand Down Expand Up @@ -531,6 +530,21 @@ - (void)setIndicatorMargin:(CGFloat)indicatorMargin
[self setNeedsDisplay];
}

- (void)setMinHeight:(CGFloat)minHeight
{
if (minHeight == _minHeight) {
return;
}

// Absolute minimum height of the control is the indicator diameter
if (minHeight < _indicatorDiameter) {
minHeight = _indicatorDiameter;
}

_minHeight = minHeight;
[self setNeedsLayout];
}

- (void)setNumberOfPages:(NSInteger)numberOfPages
{
if (numberOfPages == _numberOfPages) {
Expand Down

0 comments on commit f4fa3bc

Please sign in to comment.