溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

關(guān)于UIMenuController的一個(gè)小示例

發(fā)布時(shí)間:2020-10-22 17:17:03 來源:網(wǎng)絡(luò) 閱讀:1209 作者:zql5666641 欄目:移動(dòng)開發(fā)

 今天天氣好熱  一整天都是暈的 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問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI