我基本上想做的我们有一个UIImage
全局对象,然后我想有多个带有背景图像的UIButton
,如果选择这些图像,则会保存到全局UIImage
中。
然后,我想从所选按钮中获取保存的图像,并使用它来设置其他UIButton
的背景图像。
我该怎么做?
如果您将背景图像设置为UIButton
那么您可以使用
设置图像
[yourBtn setBackgroundImage:image forState:UIControlStateNormal];
获取图像
UIImage *image=[yourBtn backgroundImageForState:UIControlStateNormal];
或
如果要将图像(使用setImage
)设置为UIButton
则
UIImage *image=yourBtn.imageView.image;
将 AppDelegate 类用于应用全局 UIImage。
然后,当您要将此UIImage设置为UIButtons的背景时,请使用以下方法:
- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state
接口参考