Adding a button inside an image

advertisements

CGRect frame = CGRectMake(round((self.view.bounds.size.width - kImageWidth) / 2.0), kTopPlacement, kImageWidth, kImageHeight); self.containerView = [[[UIView alloc] initWithFrame:frame] autorelease]; [self.view addSubview:self.containerView];

// create the initial image view
frame = CGRectMake(0.0, 0.0, kImageWidth, kImageHeight);
self.mainView = [[[UIImageView alloc] initWithFrame:frame] autorelease];
self.mainView.image = [UIImage imageNamed:imagePath];

I want to put a button inside mainview.image. How can I do it?

Any help will be greatly appreciated.


you have to create one button.

and add mainView as a subview to that button using code:

 [btnButton addSubView:mainView];

and add this button as a subview to your ViewContoller 's view

[self.view addSubView:btnButton];