将UIImage 从UI按钮保存到对象UIImage以复制到其他UIButtons



我基本上想做的我们有一个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

接口参考

最新更新