IOS-UIButton

@interface ViewController ()

 

@property(nonatomic,strong)UIButton * button;

-(void)btnshort;  //短按回调方法

-(void)btnlong:(UILongPressGestureRecognizer*)gestureRecognizer;//长按回调方法

 

@end

 

@implementation ViewController

-(void)viewDidLoad{

 

self.button = [UIButton buttonWithType:UIButtonTypeCustom];

self.button.frame = CGRectMake(40, 100, 60, 60);

self.button.backgroundColor = [UIColor redColor];

//button点击时间

[self.button addTarget:self action:@selector(btnshort)forControlEvents:UIControlEventTouchUpInside];

//button长按事件

UILongPressGestureRecognizer * longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:selfaction:@selector(btnlong:)];

longPress.minimumPressDuration = 0.8;//定义按的时间

[self.button addGestureRecognizer:longPress];

[self.view addSubview:self.button];

}

-(void)btnshort

{

          NSLog(@"短按事件");

}

-(void)btnlong:(UILongPressGestureRecognizer*)gestureRecognizer

{

         if ([gestureRecognizer state] == UIGestureRecognizerStateBegan)

        {

              NSLog(@"长按事件");

              UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"消息"message:@"确定删除图片吗?" delegate:self cancelButtonTitle:@"确               定"otherButtonTitles: nil];

           [alert show];

}

}

posted @ 2015-08-23 19:26  大胖子2015  阅读(102)  评论(0编辑  收藏  举报