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

4th*_*ace 4 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.backgroundColor = [UIColor clearColor];
self.ball.contentMode = UIViewContentModeScaleAspectFill;
Run Code Online (Sandbox Code Playgroud)

UIImageView方块有一个白色背景,球不显示.意思是四个角落.IB版本在运行时没有显示白色背景而程序版本有什么区别?

Ben*_*tow 6

self.ball.opaque = NO;除了设置要清除的背景颜色外,还要确保设置.否则,仍会绘制白色背景.我相信你必须设置这两个是否使用IB或Xcode来创建视图 - 但IB可能已经为你设置它们.