怎么根据tag值取出相应的控件

143 阅读1分钟
原文链接: blog.csdn.net
//根据tag查找
[objc] view plain copy print?
  1. UILabel *find_label = (UILabel *)[self.view  viewWithTag:123];   
  2. find_label.backgroundColor = [UIColor redColor];  
UILabel *find_label = (UILabel *)[self.view viewWithTag:123]; 
find_label.backgroundColor = [UIColor redColor];


我觉得在循环 遍历用tag标记,查找比较常见
//另一种根据tag查找

[objc] view plain copy print?
  1. for (UIView *find_label in self.view .subviews) {  
  2.   
  3. if (find_label.tag == 123)  
  4.   
  5. {  
  6.   
  7. find_label.backgroundColor = [UIColor redColor];  
  8.   
  9. }  
  10.   
  11. }  
for (UIView *find_label in self.view.subviews) {

if (find_label.tag == 123)

{

find_label.backgroundColor = [UIColor redColor];

}

}