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