189 8069 5689

关于UIMenuController的一个小示例

 今天天气好热  一整天都是晕的 oh mygod

泰和网站制作公司哪家好,找成都创新互联!从网页设计、网站建设、微信开发、APP开发、响应式网站建设等网站项目制作,到程序开发,运营维护。成都创新互联于2013年创立到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选成都创新互联

//

//  PLViewController.m

//  MenuView

//

//  Created by apple-zql on 13-4-18.

//  Copyright (c) 2013年 apple-zql. All rights reserved.

//

 

#import"PLViewController.h"

 

@interfacePLViewController ()

 

@end

 

@implementation PLViewController

 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

       // Custom initialization

    }

   returnself;

}

 

- (void)viewDidLoad

{

    [superviewDidLoad];

// Do any additional setup after loading the view.

    UIButton *myBtn = [[UIButton alloc] init];

    myBtn.frame = CGRectMake(100, 100, 100, 20);

    [myBtnsetTitle:@"你好"forState:UIControlStateNormal];

    myBtn.backgroundColor = [UIColorblackColor];

    [myBtnaddTarget:selfaction:@selector(showMenu:)forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:myBtn];

    [myBtn release];

}

 

- (void) showMenu:(id)sender

{

    [selfbecomeFirstResponder];

   UIMenuController *menu = [UIMenuControllersharedMenuController];

    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];

    [menusetTargetRect:CGRectMake(10,10,30,30)inView:self.view];

    [menusetMenuVisible:YESanimated:YES];

    

}

 

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender

{

    if (action == @selector(click:)) {

        return YES;//显示

    }else if(action == @selector(click1:)){

        return YES;

    }

   returnNO;//不显示

}

 

 

- (void) click1:(id)sender{

   UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"1111"message:@"1111"delegate:selfcancelButtonTitle:@"OK"otherButtonTitles:nil];

    [alert show];

}

 

 

- (void) click:(id)sender{

   UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"2222"message:@"2222"delegate:selfcancelButtonTitle:@"OK"otherButtonTitles:nil];

    [alert show];

 

}

 

 

- (BOOL)canBecomeFirstResponder{

   returnYES;

}

 

- (void)didReceiveMemoryWarning

{

    [superdidReceiveMemoryWarning];

   // Dispose of any resources that can be recreated.

}

 

 

@end


当前标题:关于UIMenuController的一个小示例
标题来源:http://jkwzsj.com/article/ppggsh.html

其他资讯