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

View Code
 1     UIImageView *backImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height-UITABBAR_HEIGHT-216-39, 320, 43) ];
 2     [backImageView setUserInteractionEnabled:YES];//使添加其上的button有点击事件
 3     [backImageView setImage:[UIImage imageNamed:@"navigationBar.png"]];
 4     [backScroll addSubview:backImageView];
 5     
 6     UIButton *loginButton = [UIButton alloc];
 7     [loginButton setFrame:CGRectMake(10, 0, 40, 43)];
 8     [loginButton setTitle:@"hello" forState:UIControlStateNormal];
 9     [loginButton addTarget:self action:@selector(loginOrLogout) forControlEvents:UIControlEventTouchUpInside];
10     [backImageView addSubview:loginButton

以上代码是在一张图片上面添加按钮,并让按钮在图片上面能够响应按钮的事件的做法。

posted on 2012-10-10 11:45  呓语若梦半浮生  阅读(953)  评论(0编辑  收藏  举报

导航