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
以上代码是在一张图片上面添加按钮,并让按钮在图片上面能够响应按钮的事件的做法。