diff --git a/GHContextMenu/GHContextMenuView.h b/GHContextMenu/GHContextMenuView.h old mode 100644 new mode 100755 index 51975b6..5090c02 --- a/GHContextMenu/GHContextMenuView.h +++ b/GHContextMenu/GHContextMenuView.h @@ -34,6 +34,7 @@ typedef NS_ENUM(NSInteger, GHContextMenuActionType){ @required - (NSInteger) numberOfMenuItems; - (UIImage*) imageForItemAtIndex:(NSInteger) index; +- (NSString *) titleForItemAtIndex:(NSInteger) index; @optional -(BOOL) shouldShowMenuAtPoint:(CGPoint) point; diff --git a/GHContextMenu/GHContextMenuView.m b/GHContextMenu/GHContextMenuView.m old mode 100644 new mode 100755 index bf7c93a..117136f --- a/GHContextMenu/GHContextMenuView.m +++ b/GHContextMenu/GHContextMenuView.m @@ -11,8 +11,8 @@ #define GHShowAnimationID @"GHContextMenuViewRriseAnimationID" #define GHDismissAnimationID @"GHContextMenuViewDismissAnimationID" -NSInteger const GHMainItemSize = 44; -NSInteger const GHMenuItemSize = 40; +NSInteger const GHMainItemSize = 54; +NSInteger const GHMenuItemSize = 50; NSInteger const GHBorderWidth = 5; CGFloat const GHAnimationDuration = 0.2; @@ -23,6 +23,7 @@ @interface GHMenuItemLocation : NSObject @property (nonatomic) CGPoint position; @property (nonatomic) CGFloat angle; +@property (nonatomic,strong)NSString * itemTitle; @end @@ -45,6 +46,7 @@ @interface GHContextMenuView () @property (nonatomic) CGPoint curretnLocation; @property (nonatomic, strong) NSMutableArray* menuItems; +@property (nonatomic, strong) NSMutableArray * menuItemTitles; @property (nonatomic) CGFloat radius; @property (nonatomic) CGFloat arcAngle; @@ -79,6 +81,7 @@ - (id)init _menuItems = [NSMutableArray array]; _itemLocations = [NSMutableArray array]; + _menuItemTitles = [NSMutableArray array]; _arcAngle = M_PI_2; _radius = 90; @@ -192,6 +195,9 @@ - (void) hideMenu [self animateMenu:NO]; [self setNeedsDisplay]; [self removeFromSuperview]; + for (UIView * view in self.subviews) { + [view removeFromSuperview]; + } } } @@ -227,6 +233,7 @@ - (void) setDataSource:(id)dataSource - (void) reloadData { [self.menuItems removeAllObjects]; + [self.menuItemTitles removeAllObjects]; [self.itemLocations removeAllObjects]; if (self.dataSource != nil) { @@ -235,7 +242,11 @@ - (void) reloadData UIImage* image = [self.dataSource imageForItemAtIndex:i]; CALayer *layer = [self layerWithImage:image]; [self.layer addSublayer:layer]; + NSString * title = [self.dataSource titleForItemAtIndex:i]; + [self.menuItems addObject:layer]; + [self.menuItemTitles addObject:title]; + } } } @@ -266,6 +277,16 @@ - (void) layoutMenuItems CGFloat angle = [UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft ? M_PI_2 : -M_PI_2; layer.transform = CATransform3DRotate(CATransform3DIdentity, angle, 0, 0, 1); } + + UILabel * lbl = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, GHMainItemSize, 20.0)]; + + lbl.text = [self.menuItemTitles objectAtIndex:i]; + lbl.textColor = [UIColor whiteColor]; + lbl.font = [UIFont systemFontOfSize:12.0]; + lbl.textAlignment = NSTextAlignmentCenter; + lbl.center = CGPointMake(location.position.x, location.position.y+GHMainItemSize/2 +10); + [self addSubview:lbl]; + } } diff --git a/GHContextMenu/GHViewController.m b/GHContextMenu/GHViewController.m index c6db62c..8540bf3 100644 --- a/GHContextMenu/GHViewController.m +++ b/GHContextMenu/GHViewController.m @@ -67,7 +67,30 @@ -(UIImage*) imageForItemAtIndex:(NSInteger)index } return [UIImage imageNamed:imageName]; } - +-(NSString *)titleForItemAtIndex:(NSInteger)index{ + NSString* title = nil; + switch (index) { + case 0: + title = @"facebook-white"; + break; + case 1: + title = @"twitter-white"; + break; + case 2: + title = @"google-plus-white"; + break; + case 3: + title = @"linkedin-white"; + break; + case 4: + title = @"pinterest-white"; + break; + + default: + break; + } + return title; +} - (void) didSelectItemAtIndex:(NSInteger)selectedIndex forMenuAtPoint:(CGPoint)point { NSString* msg = nil; diff --git a/README.md b/README.md index 6ef172f..a82d08f 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ![alt tag](https://github.com/GnosisHub/GHContextMenu/blob/master/cmocv.gif) ![alt tag](https://github.com/GnosisHub/GHContextMenu/blob/master/cmocv5.gif) ![alt tag](https://github.com/GnosisHub/GHContextMenu/blob/master/cmov.gif) - +![alt tag](https://github.com/hennychen/GHContextMenu/blob/master/titles.gif) This is user friendly solution for showing context menu upon long press. It is inspired from the Pinterest iOS app ##How To Use @@ -50,6 +50,31 @@ Sample app contains examples of how to add context menu for UIView and UICollect } return [UIImage imageNamed:imageName]; } +-(NSString *)titleForItemAtIndex:(NSInteger)index{ + NSString* title = nil; + switch (index) { + case 0: + title = @"facebook-white"; + break; + case 1: + title = @"twitter-white"; + break; + case 2: + title = @"google-plus-white"; + break; + case 3: + title = @"linkedin-white"; + break; + case 4: + title = @"pinterest-white"; + break; + + default: + break; + } + + return title; +} - (void) didSelectItemAtIndex:(NSInteger)selectedIndex forMenuAtPoint:(CGPoint)point { diff --git a/titles.gif b/titles.gif new file mode 100644 index 0000000..92452af Binary files /dev/null and b/titles.gif differ