我在情节提要上有 3 种控件类型(bigButton0....bigButton11、btnSmall0...btnSmall11 和 lbl0...lbl11)。
我想将相同的图像分配给所有 btnBig0 到 btnBig11。我目前正在使用冗长的冗余代码来执行此操作,因为我没有找到任何更智能的解决方案,但我需要在运行时执行此操作。
有人可以告诉我如何缩短我的代码吗?非常感谢你。
NSString * sImageName = [NSString stringWithFormat:@"button_bg_%.0f_%.0f_normal.png", L_CELL_W, L_CELL_H];
[bigButton0 setImage:[UIImage imageNamed:sImageName] forState:UIControlStateNormal];
[bigButton1 setImage:[UIImage imageNamed:sImageName] forState:UIControlStateNormal];
[bigButton2 setImage:[UIImage imageNamed:sImageName] forState:UIControlStateNormal];
[bigButton3 setImage:[UIImage imageNamed:sImageName] forState:UIControlStateNormal];
[bigButton4 setImage:[UIImage imageNamed:sImageName] forState:UIControlStateNormal];
[bigButton5 setImage:[UIImage imageNamed:sImageName] forState:UIControlStateNormal];
[bigButton6 setImage:[UIImage imageNamed:sImageName] forState:UIControlStateNormal];
[bigButton7 setImage:[UIImage imageNamed:sImageName] forState:UIControlStateNormal];
[bigButton8 setImage:[UIImage imageNamed:sImageName] forState:UIControlStateNormal];
[bigButton9 setImage:[UIImage imageNamed:sImageName] forState:UIControlStateNormal];
[bigButton10 setImage:[UIImage imageNamed:sImageName] forState:UIControlStateNormal];
[bigButton11 setImage:[UIImage imageNamed:sImageName] forState:UIControlStateNormal];
sImageName = [NSString stringWithFormat:@"button_bg_%.0f_%.0f_down.png", L_CELL_W, L_CELL_H];
[bigButton0 setImage:[UIImage imageNamed:sImageName] forState:UIControlStateHighlighted];
[bigButton1 setImage:[UIImage imageNamed:sImageName] forState:UIControlStateHighlighted];
[bigButton2 setImage:[UIImage imageNamed:sImageName] forState:UIControlStateHighlighted];
[bigButton3 setImage:[UIImage imageNamed:sImageName] forState:UIControlStateHighlighted];
[bigButton4 setImage:[UIImage imageNamed:sImageName] forState:UIControlStateHighlighted];
[bigButton5 setImage:[UIImage imageNamed:sImageName] forState:UIControlStateHighlighted];
[bigButton6 setImage:[UIImage imageNamed:sImageName] forState:UIControlStateHighlighted];
[bigButton7 setImage:[UIImage imageNamed:sImageName] forState:UIControlStateHighlighted];
[bigButton8 setImage:[UIImage imageNamed:sImageName] forState:UIControlStateHighlighted];
[bigButton9 setImage:[UIImage imageNamed:sImageName] forState:UIControlStateHighlighted];
[bigButton10 setImage:[UIImage imageNamed:sImageName] forState:UIControlStateHighlighted];
[bigButton11 setImage:[UIImage imageNamed:sImageName] forState:UIControlStateHighlighted];