-(void)mybuttonclick{
UGFloat p=120;
for(int i=0;i<3;i++){
UIButton *aa = [UIButton buttonWithType:UIButtonTypeCustom];
if(i==0){
NSString *name=[[NSString alloc]initWithString@"ZERO"];
}else if(i==1){
NSString *name=[[NSString alloc]initWithString@"ONE"];
}else if(i==2){
NSString *name=[[NSString alloc]initWithString@"Two"];
}else{
NSString *name=[[NSString alloc]initWithString@"Three"];
}
[aa setFrame:CGRectMake(0.0f, 0.0f, 500.0f, 40.0f)];
[aa setCenter:CGPointMake(100.0f,p)];
[aa setBackgroundColor:[UIColor blueColor]];
[aa addTarget:self action:@selector(fullscreen:) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:aa];
p=p+50;
}
}
//----------------fullscreen method--------------------
-(void) fullscreen:(id)sender{
NSLog(@"button pressed on %@",[sender Stringvalue]);
}
在这里,我动态创建了 3 个 UIButton。当我按下第一个按钮时,我想显示ZERO
. 按第二个时,打印ONE
... 然后Two
,然后Three
。我怎样才能做到这一点?我知道可以使用选择器键工作来完成,但我不知道如何。