我有一個應用程序,我想檢測觸摸按鈕,如第一觸摸,第二觸摸。可能嗎?是否可以檢測按鈕的觸摸?
0
A
回答
0
4
下面是做這件事..
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];
然後在buttonPressed的方法,你可以從中總結出觸摸
-(void)buttonPressed
{
touchCount++;
// Do something or not
}
是。下一個問題。 – 2011-04-08 12:18:26