动态添加UIButton,传参数

– (void)viewDidLoad

{

[super viewDidLoad];

NSInteger left = 0;

for (NSInteger i=0; i<3; i++) {

testBtn = [[UIButton alloc]initWithFrame:CGRectMake(left, 0, 50, 50)];

testBtn.backgroundColor = [UIColor blueColor];

testBtn.tag=i;

[testBtn addTarget:self action:@selector(chicks:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:testBtn];

left += 60;

}

// Do any additional setup after loading the view, typically from a nib.

}

 

-(void)chicks:(UIButton *)btn{

NSLog(@”%i”,btn.tag);

}

(以上代码中 btn.tag = testBtn.tag)

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注