views:

36

answers:

2

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.

A: 

Might be easier to use a UIButton and add the image as the background.

Look at the section on Configuring Button With Images

You could also add a clear button (using the UIButtonTypeCustom) on top of the UIImageView if you want the button to only take up part of the image.

A: 

Hi Sharreth

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];
yakub_moriss
It is working now!! Thanks a lot!!
iSharreth