2011-08-31 118 views

回答

7

假设他们都子视图(第一级子)滚动视图中,而不是在它里面容器的观点...

for(UIView *subview in theScrollView.subviews) 
    if([subview isKindOfClass:[UILabel class]]) 
     [(UILabel *)subview setTextColor:[UIColor whateverColor]]; 

如果标签滚动视图内的其他意见里面,你将不得不缓存到每个子视图中,并执行相同的操作,但这是从上面简单的步骤。例如:

- (void)recolorLabelSubviews:(UIView *)view 
{ 
    for(UIView *subview in view.subviews) 
    { 
     if([subview isKindOfClass:[UILabel class]]) 
      [(UILabel *)subview setTextColor:[UIColor whateverColor]]; 
     else 
      [self recolorLabelSubviews:subview]; 
     // this doesn't handle the case where you have a label as a subview of a label 
     // if for some reason you're doing that, just move the [self recolorEtc:] call out of the "else" block 
    } 
} 

// then, wherever you want to recolor every label in the scroll view... 

[self recolorLabelSubviews:theScrollView]; 
+0

谢谢,这帮助了,但我仍然面临一个问题:我想改变的标记是通过一个循环中添加的UIViews的子视图。现在,如果我说循环改变了这个UIView中的标签,只有通过循环添加的最后一个UIView改变了它的颜色 - 任何想法? – kopproduction

+0

也许将所有UIViews添加到一个容器对象,因为它们是创建? – Daniel

+0

工作完美,我不能够感谢你! – kopproduction

0

尝试

for (UILabel *lbl in [self.view subviews]) { 
    if([lbl isKindOfClass:[UILabel class]]) 
    { 
     lbl.backgroundColor=[UIColor yellowColor]; 
    } 
}