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
1 change: 1 addition & 0 deletions GHContextMenu/GHContextMenuView.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 23 additions & 2 deletions GHContextMenu/GHContextMenuView.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,6 +23,7 @@ @interface GHMenuItemLocation : NSObject

@property (nonatomic) CGPoint position;
@property (nonatomic) CGFloat angle;
@property (nonatomic,strong)NSString * itemTitle;

@end

Expand All @@ -45,6 +46,7 @@ @interface GHContextMenuView ()<UIGestureRecognizerDelegate>
@property (nonatomic) CGPoint curretnLocation;

@property (nonatomic, strong) NSMutableArray* menuItems;
@property (nonatomic, strong) NSMutableArray * menuItemTitles;

@property (nonatomic) CGFloat radius;
@property (nonatomic) CGFloat arcAngle;
Expand Down Expand Up @@ -79,6 +81,7 @@ - (id)init

_menuItems = [NSMutableArray array];
_itemLocations = [NSMutableArray array];
_menuItemTitles = [NSMutableArray array];
_arcAngle = M_PI_2;
_radius = 90;

Expand Down Expand Up @@ -192,6 +195,9 @@ - (void) hideMenu
[self animateMenu:NO];
[self setNeedsDisplay];
[self removeFromSuperview];
for (UIView * view in self.subviews) {
[view removeFromSuperview];
}
}
}

Expand Down Expand Up @@ -227,6 +233,7 @@ - (void) setDataSource:(id<GHContextOverlayViewDataSource>)dataSource
- (void) reloadData
{
[self.menuItems removeAllObjects];
[self.menuItemTitles removeAllObjects];
[self.itemLocations removeAllObjects];

if (self.dataSource != nil) {
Expand All @@ -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];

}
}
}
Expand Down Expand Up @@ -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];

}
}

Expand Down
25 changes: 24 additions & 1 deletion GHContextMenu/GHViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
{
Expand Down
Binary file added titles.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.