Reputation: 71
I have an app and i want to detect touches on a button like first touch, second touch. Is it possible?
Upvotes: 0
Views: 288
Reputation: 21760
Here's one way to do it..
UIButton *sampleButton = [UIButton buttonWithType:UIButtonTypeCustom];
[sampleButton setFrame:CGRectMake(100, 100, 100, 52)];
[sampleButton setTitle:@"Button Title" forState:UIControlStateNormal];
[sampleButton setFont:[UIFont boldSystemFontOfSize:20]];
[sampleButton setBackgroundImage:[[UIImage imageNamed:@"redButton.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
[sampleButton addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:sampleButton];
Then in the method buttonPressed you can tally up the touches
-(void)buttonPressed
{
touchCount++;
// Do something or not
}
Upvotes: 4