gpt4 book ai didi

ios - 为什么不显示 Images.xcassets 中的图像?

转载 作者:行者123 更新时间:2023-11-29 10:28:36 29 4
gpt4 key购买 nike

我的Images.xcassets中有一些图片资源。最近在iPhone/iPad设备上测试时无法在应用程序中显示。

我猜它们在构建和打包时没有被复制到 Bundle 中。然后我检查在构建阶段复制捆绑资源Images.xcassets 在这里。一种奇怪的情况是它在模拟器中运行良好,但在真实设备中却失败了。为了干净的测试,每次我都会删除应用程序然后再次运行。

部分片段如下:

   UIButton *button_Share = [[UIButton alloc]initWithFrame:CGRectMake(13,33,64,20)];
[button_Share setBackgroundColor:[UIColor clearColor]];
[button_Share setUserInteractionEnabled:YES];
[button_Share setImage:[UIImage imageNamed:@"share_btnM@2x.png"] forState:UIControlStateNormal];
[button_Share addTarget:self action:@selector(click_Share) forControlEvents:UIControlEventTouchUpInside];
[imageview_ButtonBg addSubview:button_Share];

UIButton *button_AddTo = [[UIButton alloc]initWithFrame:CGRectMake(112,33,97,20)];
[button_AddTo setBackgroundColor:[UIColor clearColor]];
[button_AddTo setUserInteractionEnabled:YES];
[button_AddTo setImage:[UIImage imageNamed:@"add_cart_btnM@2x.png"] forState:UIControlStateNormal];
[button_AddTo addTarget:self action:@selector(click_AddToCart) forControlEvents:UIControlEventTouchUpInside];
[imageview_ButtonBg addSubview:button_AddTo];

UIButton *button_Buy = [[UIButton alloc]initWithFrame:CGRectMake(243,33,64,20)];
[button_Buy setBackgroundColor:[UIColor clearColor]];
[button_Buy setUserInteractionEnabled:YES];
[button_Buy setImage:[UIImage imageNamed:@"buynow_btnM@2x.png"] forState:UIControlStateNormal];
[button_Buy addTarget:self action:@selector(click_Buy) forControlEvents:UIControlEventTouchUpInside];
[imageview_ButtonBg addSubview:button_Buy];

图像集中的图像如下: enter image description here enter image description here

如有任何帮助,我们将不胜感激。

最佳答案

问题是你没有理解 Assets 目录的原理。他们将图像集的名称赋予其 Assets 。您不再使用旧的基于尺寸的图像名称。这就是 Assets 目录的全部意义所在!您使用一个名称,并为您选择适合您的硬件的正确 Assets 。

因此,例如,这个调用是错误的:

[UIImage imageNamed:@"share_btnM@2x.png"]

您的图片集名为 share_btnM,因此您可以简单地说:

[UIImage imageNamed:@"share_btnM"]

您需要检查所有代码,找到所有 imageNamed: 调用,并在所有地方修复它。然后你的图像就可以工作了。

关于ios - 为什么不显示 Images.xcassets 中的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30883837/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com