一、添加标记 (标记不能为0)
UIButton *backBtn = [[UIButton alloc] initWithFrame:CGRectMake(,,,)];
backBtn.backgroundColor = [UIColor blackColor];
backBtn.tag = ;
[self.view addSubview:backBtn];
二、取出控件
// 方法一
for (UIButton *find_Btn in self.view.subviews) { if (find_Btn.tag == ){
find_Btn.backgroundColor = [UIColor whiteColor];
}
if (find_Btn.tag == ){
find_Btn.backgroundColor = [UIColor greenColor];
} }
// 方法二
UIButton *find_Btn = (UIButton*)[self.view viewWithTag:];
find_Btn.backgroundColor = [UIColor redColor];