1、网上下载KxMenu的源码,两个文件,一个.h一个.m文件
@implementation ViewController
{
UIButton* _btn1;
}
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
-(void)loadView
{
CGRect frame = [[UIScreen mainScreen] applicationFrame];
self.view = [[UIView alloc] initWithFrame:frame];
self.view.backgroundColor = [UIColor whiteColor];
self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
_btn1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
_btn1.frame = CGRectMake(5, 5, 100, 50);
[_btn1 setTitle:@"KxMenu Test" forState:UIControlStateNormal];
[_btn1 addTarget:self action:@selector(showMenu:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_btn1];
}
- (void)viewDidLoad {
[super viewDidLoad];
}
-(void)showMenu:(UIButton*)sender
{
NSArray* menuItems =
@[
[KxMenuItem menuItem:@"Action Menu Test" image:nil target:nil action:NULL],
[KxMenuItem menuItem:@"Share this" image:[UIImage imageNamed:@"calendar_edit"] target:self action:@selector(pushMenuItem:)],
[KxMenuItem menuItem:@"Check menu" image:[UIImage imageNamed:@"calendar_edit_delete"] target:self action:@selector(pushMenuItem:)],
[KxMenuItem menuItem:@"Reload Page" image:[UIImage imageNamed:@"calendar_edit_save"] target:self action:@selector(pushMenuItem:)],
[KxMenuItem menuItem:@"Search" image:[UIImage imageNamed:@"icon_action_save_dark"] target:self action:@selector(pushMenuItem:)],
[KxMenuItem menuItem:@"Go Home" image:[UIImage imageNamed:@"icon_query_ss"] target:self action:@selector(pushMenuItem:)],
];
KxMenuItem* first = menuItems[0];
first.foreColor = [UIColor colorWithRed:47/255 green:112/255 blue:225/255 alpha:1.0];
first.alignment = NSTextAlignmentCenter;
[KxMenu setTintColor:[UIColor grayColor]];
[KxMenu showMenuInView:self.view fromRect:sender.frame menuItems:menuItems];
}
-(void)pushMenuItem:(id)sender
{
NSLog(@"%@",sender);
}