I have an imageView and within it I put a button. I have two questions:
- How can I properly add a button without losing its functionality?
- How can I refer to my
imageViewwithin the method to animate the view?
The code:
- (void)viewDidLoad
{
[super viewDidLoad];
UIImageView *grayFrame = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"expSqrGray.png"]];
[self.view addSubview:grayFrame];
grayFrame.frame = CGRectOffset(grayFrame.frame, 0, 0);
UIButton *testButton = [UIButton buttonWithType:UIButtonTypeCustom];
testButton.frame = CGRectMake(20, 20, 200, 44);
testButton.backgroundColor = [UIColor blackColor];
[testButton setTitle:@"Test" forState:UIControlStateNormal];
[testButton addTarget:self action:@selector(tapped:) forControlEvents:UIControlEventTouchUpInside];
[grayFrame addSubview:testButton];
//[self.view addSubview:testButton];
}
I have little to no knowledge about Objective-C but what you probably want to do is to make
grayFrameandtestButtonmember variables of your class. That way, your whole class has access to those two objects.For example:
You can then have another method referring to either one of them.