Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在运行时删除UIImageView中的图像背景_Iphone_Cocoa Touch_Interface Builder_Uiimageview_Uiimage - Fatal编程技术网

Iphone 在运行时删除UIImageView中的图像背景

Iphone 在运行时删除UIImageView中的图像背景,iphone,cocoa-touch,interface-builder,uiimageview,uiimage,Iphone,Cocoa Touch,Interface Builder,Uiimageview,Uiimage,我在Interface Builder中将一个球分配给UIImageView。UIImageView的IBOutlet连接到相应的UIViewController。图像具有白色背景。当我将其指定给IB中的UIImageView时,背景是透明的。在IB中,我将UIImageView设置为透明背景和方面填充 在运行时为UIImageView分配图像时: self.ball.image = ballImage; //ballImage is a UIImage self.ball.background

我在Interface Builder中将一个球分配给UIImageView。UIImageView的IBOutlet连接到相应的UIViewController。图像具有白色背景。当我将其指定给IB中的UIImageView时,背景是透明的。在IB中,我将UIImageView设置为透明背景和方面填充

在运行时为UIImageView分配图像时:

self.ball.image = ballImage; //ballImage is a UIImage
self.ball.backgroundColor = [UIColor clearColor];
self.ball.contentMode = UIViewContentModeScaleAspectFill;

UIImageView正方形有一个白色背景,球不显示。意思是四个角。IB版本在运行时不显示白色背景与编程版本显示白色背景有什么区别?

如果需要以编程方式删除背景,请参阅指南。在这一点上我没有其他想法…只是使用CGImageCreateWithMaskingColor


如果您的*.PNG(或任何图形资源文件)没有内置的透明度(只有白色背景),但使用IB,它看起来是透明的-UIImageView的alpha属性可能小于1,您会看到部分透明的图像。

请确保设置了
self.ball.opaque=NO除了将背景色设置为“清除”之外。否则,仍将绘制白色背景。我相信无论使用IB还是Xcode创建视图,您都必须同时设置这两个选项,但IB可能已经为您设置了这两个选项。

谢谢这两个建议。是我的错。有一个PNG版本的JPG,有透明的背景。IB在使用PNG,而我在以编程方式使用JPG。啊!然而,如果图像没有透明的背景,你就不能用简单的方法来处理它。不透明不会改变它。我还尝试设置不透明度,包括石英框架和self.ball.layer.opacity=0.0f;但又是一次失败。修改图像是最简单的方法。