From 87ffa488000efdacd3376ebbb13029ef8ab088b5 Mon Sep 17 00:00:00 2001 From: Eric Shi Date: Tue, 15 Oct 2013 17:31:28 +0800 Subject: [PATCH 1/3] Add kxMenuItem selected custom. 1. add selectedColor for kxMenuItem 2. add + (UIImage *)createImageFromColor:(UIColor *)color funtion 3. manage upside here :- (UIView *) mkContentView 4. update example usage --- KxMenuExample/ViewController.m | 9 ++++++--- Source/KxMenu.h | 1 + Source/KxMenu.m | 28 +++++++++++++++++++++++----- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/KxMenuExample/ViewController.m b/KxMenuExample/ViewController.m index 3d254a3..d5eec0d 100644 --- a/KxMenuExample/ViewController.m +++ b/KxMenuExample/ViewController.m @@ -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:)], @@ -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]; diff --git a/Source/KxMenu.h b/Source/KxMenu.h index 0de0c5d..53d29ed 100644 --- a/Source/KxMenu.h +++ b/Source/KxMenu.h @@ -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 diff --git a/Source/KxMenu.m b/Source/KxMenu.m index bdfb6a3..c20a17e 100644 --- a/Source/KxMenu.m +++ b/Source/KxMenu.m @@ -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]; @@ -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]; } @@ -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}; From 354393455a9f64094dba3528dff7966cb9ffe73a Mon Sep 17 00:00:00 2001 From: Eric Shi Date: Thu, 17 Oct 2013 14:53:14 +0800 Subject: [PATCH 2/3] Add CocoaPods Support add KxMenu.podspec. About 4 mouth ago, KxMenu.podspec was push to Spec, I updated it. --- KxMenu.podspec | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 KxMenu.podspec diff --git a/KxMenu.podspec b/KxMenu.podspec new file mode 100644 index 0000000..5355cd2 --- /dev/null +++ b/KxMenu.podspec @@ -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" => "ru.kolyvan@gmail.com", "jcccn" => "jccuestc@gmail.com"} + 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 From 3858616f8c4ca0a4bc48406a3f34bad8d5e875db Mon Sep 17 00:00:00 2001 From: Eric Shi Date: Thu, 17 Oct 2013 15:00:19 +0800 Subject: [PATCH 3/3] Update CocoaPods Install in Readme.md Update readme to add CocoaPods Installing. --- readme.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/readme.md b/readme.md index 44323d0..ed0086d 100644 --- a/readme.md +++ b/readme.md @@ -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.