UIImageView 图像未显示


_topBar = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 45)];
UIImageView *bar = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"top_bar.png"]];
bar.frame = CGRectMake(0, 0, 320, 45);
[_topBar addSubview:bar];
_up = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"up.png"]];
[_topBar addSubview:_up];

_up没有出现在我的版本中。如果我将"up.png"交换为我的资源文件夹中的任何其他图像,它会显示,但向上.png拒绝。我能做些什么吗?我只使用UIImage初始化了它,一个静态分配的UIImageView,删除并重新添加了.png文件,将它们从资源文件夹中取出并放在其他地方,重新保存它们,除了扔掉它们之外的所有内容。

编辑: 该文件被保存为已启动.png但实际上已启动.png.psd。只需阅读细则即可。

在 Finder 中检查种类。它可能不是 png,因此不会显示。

我现在知道这是真的,因为你评论了:)

有几件事。在右窗格中选择文件,打开最右边的 (3rd( 文件检查器面板,并确保此图像包含在目标中。

在代码中,分解以下内容:

UIImage *image = [UIImage imageNamed:@"up.png"];
NSLog(@"image %@", image);
_up = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"up.png"]];
NSLog(@"UP FRAME: %@", NSStringFromCGRect(_up.frame) );
// maybe set the frame to what you want?
_up.frame = (CGRect){ {0,0}, image.size }; // set origin where you want it

最新更新