iOS5 UIButton应该尝试优化背景图片吗?

时间:2011-11-06 18:33:18

标签: iphone ios memory uibutton core-animation

我在一个UIViewController上最多有16个按钮。每个按钮都有一个自定义样式,背景png图像尺寸为160x160像素(按比例缩小以用于视网膜显示)。按钮本身为40x40,60x60或80x80。我希望视图控制器能够存活很长时间。

我想为这些按钮分配3种类型的图像(红色,黄色,绿色)。计划是重新分配图像以指示状态转换。目前我的UI是在界面构建器中构建的。 Interface Builder是否足够聪明,我意识到我正在尝试为这些按钮重复使用相同的图像,还是会分配16个单独的图像,每个按钮一个?有东西告诉我每个按钮有一个单独的UILayer,以某种方式得到图像。

谢谢!

1 个答案:

答案 0 :(得分:2)

他们都使用相同的图像。您可以通过使用此方法创建UIButton的子类来轻松地对此进行测试:

- (void)awakeFromNib
{
    NSLog(@"TestButton %p - background image %p %@", self, self.currentBackgroundImage, self.currentBackgroundImage);
}

将按钮设置为UIButton子类,运行并检查输出:

2011-11-06 13:36:41.877 tester[21909:f803] TestButton 0x68522a0 - background image <UIImage: 0xed2d630>
2011-11-06 13:36:41.878 tester[21909:f803] TestButton 0xed2f1e0 - background image <UIImage: 0xed2d630>
2011-11-06 13:36:41.879 tester[21909:f803] TestButton 0xed2f6a0 - background image <UIImage: 0xed2d630>