iOSのボタンはtagによって区別されます
1224 ワード
- (void) createButton
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(20, 60, 80, 40);
[button setTitle:@" 1" forState:UIControlStateNormal];
[button setTag:22];
[self.view addSubview:button];
//[button addTarget:self action:@selector(ClickEvent) forControlEvents:UIControlEventTouchUpInside];
//
[button addTarget:self action:@selector(ClickEvent:) forControlEvents:UIControlEventTouchUpInside];
// button , Adnroid
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button2.frame = CGRectMake(20, 100, 80, 40);
[button2 setTitle:@" 2" forState:UIControlStateNormal];
[self.view addSubview:button2];
// clickevent include muitle arges
[button2 addTarget:self action:@selector(ClickEvent:) forControlEvents:UIControlEventTouchUpInside];
[button2 setTag:21];
}
//
- (void) ClickEvent
{
NSLog(@"button click event......");
}
- (void) ClickEvent:(UIButton *) button
{
NSUInteger BtnTag = [button tag];
if(BtnTag == 21)
{
NSLog(@"
button is:button2");
}
else
{
NSLog(@"
button is:button1");
}
}