1.设置当前viewcontroller 的所有UILable 的背景颜色
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self setAllLabelColor:[UIColor redColor] rootView:self.view];
}
-(void)setAllLabelColor:(UIColor*)color rootView:(UIView*)view
{
if ([view isMemberOfClass:[UILabel class]]) {
UILabel * label = (UILabel*)view;
[label setBackgroundColor:color];
}else if(view.subviews.count > 0){
for (UIView * subview in view.subviews) {
[self setAllLabelColor:color rootView:subview];
}
}
}
本文介绍了一种在iOS应用中批量设置所有UILabel背景颜色的方法。通过递归遍历UIView子视图并检查其类型,可以有效地为当前ViewController内的所有UILabel统一设置背景颜色。
2725

被折叠的 条评论
为什么被折叠?



