Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kxMenuItem selected custom & CocoaPods Support #11

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
18 changes: 18 additions & 0 deletions KxMenu.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Pod::Spec.new do |s|
s.name = "KxMenu"
s.version = "1"
s.summary = "KxMenu is a vertical popup menu for using in iOS applications."
s.description = <<-DESC
KxMenu is a vertical popup menu for using in iOS applications.
It can popup a menu where ever on the screen.
DESC
s.homepage = "https://github.com/kolyvan/kxmenu"
s.screenshots = "https://raw.github.com/kolyvan/kxmenu/master/screenshot/example.png", "https://raw.github.com/kolyvan/kxmenu/master/screenshot/example.gif"
s.license = { :type => 'Copyright', :file => 'LICENSE' }
s.authors = { "kolyvan" => "[email protected]", "jcccn" => "[email protected]"}
s.platform = :ios, '5.0'
s.source = { :git => "https://github.com/kolyvan/kxmenu.git", :tag => "v1" }
s.source_files = 'Source/KxMenu.*'
s.framework = 'UIKit'
s.requires_arc = true
end
9 changes: 6 additions & 3 deletions KxMenuExample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,13 @@ - (void)showMenu:(UIButton *)sender
{
NSArray *menuItems =
@[

[KxMenuItem menuItem:@"ACTION MENU 1234456"
image:nil
target:nil
action:NULL],

[KxMenuItem menuItem:@"Share this"
image:[UIImage imageNamed:@"action_icon"]
image:nil//[UIImage imageNamed:@"action_icon"]
target:self
action:@selector(pushMenuItem:)],

Expand Down Expand Up @@ -148,7 +147,11 @@ - (void)showMenu:(UIButton *)sender
KxMenuItem *first = menuItems[0];
first.foreColor = [UIColor colorWithRed:47/255.0f green:112/255.0f blue:225/255.0f alpha:1.0];
first.alignment = NSTextAlignmentCenter;


KxMenuItem *custom = menuItems[2];
custom.foreColor = [UIColor greenColor];
custom.selectedColor = [UIColor grayColor];

[KxMenu showMenuInView:self.view
fromRect:sender.frame
menuItems:menuItems];
Expand Down
1 change: 1 addition & 0 deletions Source/KxMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
@property (readwrite, nonatomic, weak) id target;
@property (readwrite, nonatomic) SEL action;
@property (readwrite, nonatomic, strong) UIColor *foreColor;
@property (readwrite, nonatomic, strong) UIColor *selectedColor;
@property (readwrite, nonatomic) NSTextAlignment alignment;

+ (instancetype) menuItem:(NSString *) title
Expand Down
28 changes: 23 additions & 5 deletions Source/KxMenu.m
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,8 @@ - (UIView *) mkContentView

const CGFloat titleX = kMarginX * 2 + maxImageWidth;
const CGFloat titleWidth = maxItemWidth - titleX - kMarginX * 2;
UIImage *selectedImage = [KxMenuView selectedImage:(CGSize){maxItemWidth, maxItemHeight + 2}];

UIImage *defaultSelectedImage = [KxMenuView selectedImage:(CGSize){maxItemWidth, maxItemHeight + 2}];
UIImage *gradientLine = [KxMenuView gradientLine: (CGSize){maxItemWidth - kMarginX * 4, 1}];

UIView *contentView = [[UIView alloc] initWithFrame:CGRectZero];
Expand Down Expand Up @@ -470,9 +470,14 @@ - (UIView *) mkContentView
[button addTarget:self
action:@selector(performAction:)
forControlEvents:UIControlEventTouchUpInside];

[button setBackgroundImage:selectedImage forState:UIControlStateHighlighted];


if (menuItem.selectedColor) {
UIImage *selectedImage = [KxMenuView createImageFromColor:menuItem.selectedColor];
[button setBackgroundImage:selectedImage forState:UIControlStateHighlighted];
} else {
[button setBackgroundImage:defaultSelectedImage forState:UIControlStateHighlighted];
}

[itemView addSubview:button];
}

Expand Down Expand Up @@ -568,6 +573,19 @@ - (CGPoint) arrowPoint
return point;
}

+ (UIImage *)createImageFromColor:(UIColor *)color
{
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);

UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}

+ (UIImage *) selectedImage: (CGSize) size
{
const CGFloat locations[] = {0,1};
Expand Down
29 changes: 29 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,35 @@ KxMenu is a vertical popup menu for using in iOS applications
![sample png](https://raw.github.com/kolyvan/kxmenu/master/screenshot/example.png "Sample Png")
![sample gif](https://raw.github.com/kolyvan/kxmenu/master/screenshot/example.gif "Sample Gif")

### Installing

**CocoaPods**

CocoaPods automates 3rd party dependencies in Objective-C.

Install the ruby gem.

```
$ sudo gem install cocoapods
$ pod setup
```

Depending on your Ruby installation, you may not have to run as sudo to install the cocoapods gem.
Create a Podfile. You must be running on iOS 5 or above.

```
platform :ios, '5.0'
pod 'KxMenu', '1'
```

Install dependencies.

```
$ pod install
```

When using CocoaPods, you must open the .xcworkspace file instead of the project file when building your project.

### Usage

1. Drop files from KxMenu/Source folder in your project.
Expand Down