Adding a button inside an image
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] autore开发者_JAVA百科lease];
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];
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.
精彩评论