Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.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
Xcode将.PNG图像呈现为全白色_Xcode_Png_Transparency - Fatal编程技术网

Xcode将.PNG图像呈现为全白色

Xcode将.PNG图像呈现为全白色,xcode,png,transparency,Xcode,Png,Transparency,我正在将.PNG导入xcode。图像具有透明度。从ID在按钮上渲染时,图像的所有内容(透明度除外)都将变为白色 这是一个已知的问题吗?是因为我保存.PNG的方式吗 谢谢你的帮助 要在UIBarButtonItem中显示图像,需要使用图像创建UIButton,然后将该按钮添加到UIBarButtonItem中。否则,正如你所提到的,你只会得到大纲 因此: 这就是图像在UIBarButtonItems和UIAbbarItems上的工作方式:您提供的图像仅用作透明遮罩。您可以使用UIImageView

我正在将.PNG导入xcode。图像具有透明度。从ID在按钮上渲染时,图像的所有内容(透明度除外)都将变为白色

这是一个已知的问题吗?是因为我保存.PNG的方式吗


谢谢你的帮助

要在UIBarButtonItem中显示图像,需要使用图像创建UIButton,然后将该按钮添加到UIBarButtonItem中。否则,正如你所提到的,你只会得到大纲

因此:


这就是图像在UIBarButtonItems和UIAbbarItems上的工作方式:您提供的图像仅用作透明遮罩。您可以使用UIImageView/UIButton按照AtkinsonCM的建议显示图像,也可以创建一个用作遮罩的图像


我个人认为,通常最好遵守苹果的规则,除非你有令人信服的理由不这样做,例如,用户体验将得到显著改善。

在预览等其他地方查看.png是否正确?如果你发布相关代码,可能更容易发现问题。等一下,你是在说UIButton还是UIBarButtonim?听起来像是后者。。。如果将图像加载到UIImageView中,图像是否正确显示?是的,在xcode中导入图像之前,图像在预览中看起来很好,但在界面生成器中没有,我在其中设置了按钮属性。是的,它是UIBarButtonim,如果是UIImageView,它确实正确显示
// Initialize the UIButton with your image
UIImage *myImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"someImage" ofType:@"png"]];
UIButton *myButton = [[UIButton alloc] init];
[myButton setImage:myImage forState:UIControlStateNormal];

//Then create the UIBarButton
UIBarButtonItem *aBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:aButton];