开发者

IB vs Programmatical Creation of UIButtons

开发者 https://www.devze.com 2023-03-13 06:09 出处:网络
Let\'s say I want to create a lot of custom buttons with the same UIImage named X. Programmatically, I would create only one UIImage and add this to all the开发者_如何转开发 buttons I created.

Let's say I want to create a lot of custom buttons with the same UIImage named X. Programmatically, I would create only one UIImage and add this to all the开发者_如何转开发 buttons I created. I was wondering if I created these buttons in Interface Builder would IB create only 1 UIImage X or a new UIImage X for each button? Thanks


UIImages are pooled, so repeated calls to [UIImage imageNamed:] with the same name will actually return the same UIImage instance. This should apply to objects baked into a NIB as well. Should be easy to verify, though - just print out the pointer value using

NSLog(@"%p", [button imageForState:UIControlStateNormal]);

or whatever for each button in question.

0

精彩评论

暂无评论...
验证码 换一张
取 消