温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

关于UIMenuController的一个小示例

发布时间:2020-10-22 17:17:03 来源:网络 阅读:1197 作者:zql5666641 栏目:移动开发

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

//

//  PLViewController.m

//  MenuView

//

//  Created by applezql on 13-4-18.

//  Copyright (c) 2013 applezql. 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

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI