自定义按钮并添加点击事件&自定义图片并添加点击事件

//    按钮

    UIButton *but2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    but2.frame = CGRectMake(200, 10, 65, 40);

    [but2 setTitle:@"开始" forState:UIControlStateNormal];

    but2.titleLabel.textColor= [UIColor greenColor];

    [self.view addSubview:but2];    

    [but2 addTarget:self action:@selector(text2) forControlEvents:UIControlEventTouchDown];

//    添加图片

    UIImage *img = [UIImage imageNamed:@"0000.png"];

   imgeaview = [[UIImageView alloc]initWithImage:img];

    imgeaview.frame = CGRectMake(100, 100, 88,89);

    [self.view addSubview:imgeaview];

    

    imgeaview.userInteractionEnabled = YES;//   开启图片事件

    UITapGestureRecognizer * tap = [[UITapGestureRecognizeralloc] initWithTarget:self action:@selector(text2)];//添加手指

    [imgeaview addGestureRecognizer:tap];//    添加事

    

posted @ 2013-08-23 12:01  悟性思远  阅读(512)  评论(0编辑  收藏  举报