今天天气好热 一整天都是晕的 oh mygod
//
// PLViewController.m
// MenuView
//
// Created by apple-zql on 13-4-18.
// Copyright (c) 2013年 apple-zql. All rights reserved.
//
#import "PLViewController.h"
@interface PLViewController ()
@end
@implementation PLViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UIButton *myBtn = [[UIButton alloc] init];
myBtn.frame = CGRectMake(100, 100, 100, 20);
[myBtn setTitle:@"你好" forState:UIControlStateNormal];
myBtn.backgroundColor = [UIColor blackColor];
[myBtn addTarget:self action:@selector(showMenu:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:myBtn];
[myBtn release];
}
- (void) showMenu:(id)sender
{
[self becomeFirstResponder];
UIMenuController *menu = [UIMenuController sharedMenuController];
UIMenuItem *item1 = [[UIMenuItem alloc] initWithTitle:@"1111" action:@selector(click:)];
UIMenuItem *item2 = [[UIMenuItem alloc] initWithTitle:@"2222" action:@selector(click1:)];
menu.menuItems = [NSArray arrayWithObjects:item1,item2, nil];
[menu setTargetRect:CGRectMake(10, 10, 30, 30) inView:self.view];
[menu setMenuVisible:YES animated:YES];
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(click:)) {
return YES;//显示
}else if(action == @selector(click1:)){
return YES;
}
return NO;//不显示
}
- (void) click1:(id)sender{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"1111" message:@"1111" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}
- (void) click:(id)sender{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"2222" message:@"2222" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}
- (BOOL)canBecomeFirstResponder{
return YES;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。