diff --git a/BDKCollectionIndexView.h b/BDKCollectionIndexView.h
index ec11b8a..42d33c4 100644
--- a/BDKCollectionIndexView.h
+++ b/BDKCollectionIndexView.h
@@ -24,6 +24,8 @@ typedef NS_ENUM(NSInteger, BDKCollectionIndexViewDirection) {
*/
@property (strong, nonatomic) NSArray *indexTitles;
+@property (strong, nonatomic) UIColor *colorPeekView;
+
/**
Indicates the position of the last-selected index title. Should map directly to a table view / collection section.
*/
@@ -88,4 +90,6 @@ typedef NS_ENUM(NSInteger, BDKCollectionIndexViewDirection) {
- (void)collectionIndexView:(BDKCollectionIndexView *)collectionIndexView isPressedOnIndex:(NSUInteger)pressedIndex indexTitle:(NSString *)indexTitle;
- (void)collectionIndexView:(BDKCollectionIndexView *)collectionIndexView liftedFingerFromIndex:(NSUInteger)pressedIndex;
+- (NSAttributedString *)collectionIndexView:(BDKCollectionIndexView *)collectionIndexView index:(NSUInteger )index;
+
@end
diff --git a/BDKCollectionIndexView.m b/BDKCollectionIndexView.m
index 75b83c0..bb9fb23 100644
--- a/BDKCollectionIndexView.m
+++ b/BDKCollectionIndexView.m
@@ -88,6 +88,7 @@ - (instancetype)initWithFrame:(CGRect)frame indexTitles:(NSArray *)indexTitles {
-(void)setupWithIndexTitles:(NSArray *)indexTitles {
+ _colorPeekView = [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:1];
_currentIndex = 0;
_touchStatusViewAlpha = 0.25;
_touchStatusBackgroundColor = [UIColor blackColor];
@@ -314,6 +315,44 @@ - (void)setNewIndexForPoint:(CGPoint)point {
break;
}
+ if ([self.delegate respondsToSelector:@selector(collectionIndexView:index:)]) {
+ NSAttributedString * attr = [self.delegate collectionIndexView:self index:self.currentIndex];
+ if (attr != NULL) {
+ UIView * peekView = [self viewWithTag:9999];
+ UILabel * titleLabel = [peekView viewWithTag:9998];
+ if(peekView == NULL) {
+ peekView = [UIView new];
+ peekView.layer.cornerRadius = 25;
+ peekView.layer.backgroundColor = self.colorPeekView.CGColor;
+ peekView.tag = 9999;
+ peekView.alpha = 0;
+ [self addSubview:peekView];
+
+ titleLabel = [UILabel new];
+ titleLabel.tag = 9998;
+ [peekView addSubview:titleLabel];
+ [UIView animateWithDuration:0.3 animations:^{
+ peekView.alpha = 1;
+ }];
+ }
+
+ CGFloat maxOffset = self.frame.size.height - 50;
+ CGFloat minOffset = 0;
+ CGFloat peekOffset = point.y;
+ if (peekOffset > maxOffset){
+ peekOffset = maxOffset;
+ }
+ else if (peekOffset < minOffset) {
+ peekOffset = minOffset;
+ }
+
+ peekView.frame = CGRectMake( (self.frame.size.width + 25) * -1, peekOffset, 50, 50);
+ titleLabel.frame = peekView.bounds;
+ titleLabel.attributedText = attr;
+ titleLabel.textAlignment = NSTextAlignmentCenter;
+ }
+ }
+
if (newIndex == -1) {
UILabel *topLabel = self.indexLabels[0];
UILabel *bottomLabel = self.indexLabels[self.indexLabels.count - 1];
@@ -344,6 +383,14 @@ - (void)handleGesture:(UIGestureRecognizer *)recognizer {
if (recognizer != _longPresser) { return; }
if (recognizer.state == UIGestureRecognizerStateEnded) {
+
+ UIView *peekView = [self viewWithTag:9999];
+ [UIView animateWithDuration:0.3 animations:^{
+ peekView.alpha = 0;
+ } completion:^(BOOL finished) {
+ [peekView removeFromSuperview];
+ }];
+
if ([self.delegate respondsToSelector:@selector(collectionIndexView:liftedFingerFromIndex:)]) {
[self.delegate collectionIndexView:self liftedFingerFromIndex:self.currentIndex];
}
diff --git a/Project/BDKCollectionIndexView.xcodeproj/project.pbxproj b/Project/BDKCollectionIndexView.xcodeproj/project.pbxproj
index 7976d26..9451b02 100644
--- a/Project/BDKCollectionIndexView.xcodeproj/project.pbxproj
+++ b/Project/BDKCollectionIndexView.xcodeproj/project.pbxproj
@@ -295,7 +295,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = Prefix.pch;
INFOPLIST_FILE = "$(SRCROOT)/Info.plist";
- IPHONEOS_DEPLOYMENT_TARGET = 5.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 8.0;
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
WRAPPER_EXTENSION = app;
@@ -311,7 +311,7 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = Prefix.pch;
INFOPLIST_FILE = "$(SRCROOT)/Info.plist";
- IPHONEOS_DEPLOYMENT_TARGET = 5.0;
+ IPHONEOS_DEPLOYMENT_TARGET = 8.0;
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
WRAPPER_EXTENSION = app;
diff --git a/Project/BDKCollectionIndexView.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Project/BDKCollectionIndexView.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
new file mode 100644
index 0000000..18d9810
--- /dev/null
+++ b/Project/BDKCollectionIndexView.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
@@ -0,0 +1,8 @@
+
+
+
+
+ IDEDidComputeMac32BitWarning
+
+
+
diff --git a/Project/BDKViewController.m b/Project/BDKViewController.m
index f339a75..b950d73 100644
--- a/Project/BDKViewController.m
+++ b/Project/BDKViewController.m
@@ -13,7 +13,7 @@
#import "BDKCell.h"
-@interface BDKViewController ()
+@interface BDKViewController ()
@property (strong, nonatomic) UICollectionView *collectionView;
@@ -49,6 +49,7 @@ - (void)viewDidLoad {
self.sections = sections.copy;
self.indexView.indexTitles = self.sections;
+ self.indexView.delegate = self;
}
- (void)viewWillLayoutSubviews {
@@ -129,4 +130,14 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell
return cell;
}
+
+-(NSAttributedString*)collectionIndexView:(BDKCollectionIndexView *)collectionIndexView index:(NSUInteger)index {
+
+ NSAttributedString * attr = [[NSAttributedString alloc]initWithString: self.sections[index]];
+
+ return attr;
+}
+
@end
+
+