需要两个文件 KxMenu.h KxMenu.m
用的时候在需要的文件里添加两个方法就行了。。
_btn4 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
_btn4.frame = CGRectMake(W - 105, H - 55, 100, 50);
[_btn4 setTitle:@"Click me" forState:UIControlStateNormal];
[_btn4 addTarget:self action:@selector(showMenu:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_btn4];
- (void)showMenu:(UIButton *)sender
{
NSArray *menuItems =
@[
[KxMenuItem menuItem:@"ACTION MENU"
image:nil
target:nil
action:NULL],
[KxMenuItem menuItem:@"Share this"
image:[UIImage imageNamed:@"action_icon"]
target:self
action:@selector(pushMenuItem:)],
[KxMenuItem menuItem:@"Check menu"
image:[UIImage imageNamed:@"check_icon"]
target:self
action:@selector(pushMenuItem:)],
[KxMenuItem menuItem:@"Reload page"
image:[UIImage imageNamed:@"reload"]
target:self
action:@selector(pushMenuItem:)],
[KxMenuItem menuItem:@"Search"
image:[UIImage imageNamed:@"search_icon"]
target:self
action:@selector(pushMenuItem:)],
[KxMenuItem menuItem:@"Go home"
image:[UIImage imageNamed:@"home_icon"]
target:self
action:@selector(pushMenuItem:)],
];
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;
[KxMenu showMenuInView:self.view
fromRect:sender.frame
menuItems:menuItems];
}
- (void) pushMenuItem:(id)sender
{
NSLog(@"%@", sender);
}