UIImageView上添加Button不能响应点击事件

来源:互联网 发布:淘宝七天下架什么意思 编辑:程序博客网 时间:2024/05/17 06:21

UIImageView *backImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height-UITABBAR_HEIGHT-216-39, 320, 43) ];

//因为UIImageView 默认是不接受Touch事件的 
//所以只要加上一句imgView.userInteractionEnabled = YES;

    [backImageView setUserInteractionEnabled:YES];

    [backImageView setImage:[UIImage imageNamed:@"navigationBar.png"]];

    [backScroll addSubview:backImageView];

    

    UIButton *loginButton = [UIButton alloc];

    [loginButton setFrame:CGRectMake(10, 0, 40, 43)];

    [loginButton setTitle:@"hello" forState:UIControlStateNormal];

    [loginButton addTarget:self action:@selector(loginOrLogout) forControlEvents:UIControlEventTouchUpInside];

    [backImageView addSubview:loginButton];n


0 0
原创粉丝点击