iOS 在imageview中添加按钮 并能响应消息 响应者链条

来源:互联网 发布:方舟数据修改 编辑:程序博客网 时间:2024/05/21 10:48

uiwindow--->uiview---->uiimageview(基类不是uicontrol是不接受消息的)---->uibutton-

//

//  ViewController.m

//  imageviewaddbutton

//

//  Created by tianshangrenjian on 15/7/2.

//  Copyright © 2015 tianshangrenjian. All rights reserved.

//


#import "ViewController.h"


@interface ViewController ()

@property (weak, nonatomic) IBOutletUIImageView *iconImg;


@end


@implementation ViewController

- (void)xx

{

    NSLog(@"click");

}

- (void)viewDidLoad {

    [superviewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    

    

    

    

    UIButton *bt=[UIButtonbuttonWithType:UIButtonTypeCustom];

    [bt setTitle:@"click"forState:UIControlStateNormal];

    

    [self.iconImgaddSubview:bt];

    

    

    bt.frame=CGRectMake(20,20, 80, 100);

    

    [bt setBackgroundColor:[UIColorredColor]];

    [bt addTarget:selfaction:@selector(xx)forControlEvents:UIControlEventTouchUpInside];

    

    self.iconImg.userInteractionEnabled=YES;

    

    

}


- (void)didReceiveMemoryWarning {

    [superdidReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end



0 0
原创粉丝点击