Skip to content

Commit

Permalink
Merge pull request #20 from kreeger/feature/customization-ftw
Browse files Browse the repository at this point in the history
Add ability to customize background color, alpha for touch status view.
  • Loading branch information
kreeger committed Apr 10, 2015
2 parents 3bdeb60 + f308c17 commit b69008d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
13 changes: 11 additions & 2 deletions BDKCollectionIndexView.h
Expand Up @@ -39,7 +39,16 @@ typedef NS_ENUM(NSInteger, BDKCollectionIndexViewDirection) {
*/
@property (readonly) NSString *currentIndexTitle;

@property (strong, nonatomic) UIColor *backgroundColor;
/**
The background color of the "touch status view" that appears when the view is touched.
*/
@property (strong, nonatomic) UIColor *touchStatusBackgroundColor;

/**
The amount of alpha applied to the "touch status view" that appears when the view is touched.
*/
@property (nonatomic) CGFloat touchStatusViewAlpha;
//@property (strong, nonatomic) UIColor *backgroundColor;


/**
Expand Down Expand Up @@ -71,7 +80,7 @@ typedef NS_ENUM(NSInteger, BDKCollectionIndexViewDirection) {

@optional

- (void)collectionIndexView:(BDKCollectionIndexView *)collectionIndexView isPressedOnIndex:(NSUInteger)pressedIndex;
- (void)collectionIndexView:(BDKCollectionIndexView *)collectionIndexView isPressedOnIndex:(NSUInteger)pressedIndex indexTitle:(NSString *)indexTitle;
- (void)collectionIndexView:(BDKCollectionIndexView *)collectionIndexView liftedFingerFromIndex:(NSUInteger)pressedIndex;

@end
20 changes: 12 additions & 8 deletions BDKCollectionIndexView.m
Expand Up @@ -52,8 +52,9 @@ @implementation BDKCollectionIndexView
@synthesize
delegate = _delegate,
currentIndex = _currentIndex,
direction = _direction,
backgroundColor = _backgroundColor;
touchStatusBackgroundColor = _touchStatusBackgroundColor,
touchStatusViewAlpha = _touchStatusViewAlpha,
direction = _direction;

+ (instancetype)indexViewWithFrame:(CGRect)frame indexTitles:(NSArray *)indexTitles {
return [[self alloc] initWithFrame:frame indexTitles:indexTitles];
Expand All @@ -70,8 +71,10 @@ - (instancetype)initWithFrame:(CGRect)frame indexTitles:(NSArray *)indexTitles {
}

_currentIndex = 0;
_touchStatusViewAlpha = 0.25;
_touchStatusBackgroundColor = [UIColor blackColor];
self.tintColor = [UIColor blackColor];
_backgroundColor = [UIColor clearColor];
self.backgroundColor = [UIColor clearColor];

SEL handleGestureSelector = @selector(handleGesture:);

Expand Down Expand Up @@ -244,7 +247,7 @@ - (void)buildIndexLabels {
label.tag = tag;
tag = tag + 1;
label.font = [UIFont boldSystemFontOfSize:12];
label.backgroundColor = _backgroundColor;
label.backgroundColor = self.backgroundColor;
label.textColor = self.tintColor;
label.textAlignment = NSTextAlignmentCenter;
label.isAccessibilityElement = NO;
Expand Down Expand Up @@ -282,8 +285,8 @@ - (void)setNewIndexForPoint:(CGPoint)point {
}

- (void)setBackgroundVisibility:(BOOL)flag {
CGFloat alpha = flag ? 0.25 : 0;
self.touchStatusView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:alpha];
CGFloat alpha = flag ? self.touchStatusViewAlpha : 0;
self.touchStatusView.backgroundColor = [self.touchStatusBackgroundColor colorWithAlphaComponent:alpha];
}

#pragma mark - Gestures
Expand All @@ -298,8 +301,9 @@ - (void)handleGesture:(UIGestureRecognizer *)recognizer {
[self.delegate collectionIndexView:self liftedFingerFromIndex:self.currentIndex];
}
} else {
if ([self.delegate respondsToSelector:@selector(collectionIndexView:isPressedOnIndex:)]) {
[self.delegate collectionIndexView:self isPressedOnIndex:self.currentIndex];
if ([self.delegate respondsToSelector:@selector(collectionIndexView:isPressedOnIndex:indexTitle:)]) {

[self.delegate collectionIndexView:self isPressedOnIndex:self.currentIndex indexTitle:self.currentIndexTitle];
}
}

Expand Down

0 comments on commit b69008d

Please sign in to comment.