UIImageView image not showing up

前提是你 提交于 2019-12-11 15:47:29

问题


_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 does not show up in my build. If i exchange the "up.png" for any other image in my resources folder, it shows up, but up.png refuses to. Is there anything I can do? I've initialized it using just a UIImage, a statically allocated UIImageView, removed and re-added the .png files, took them out of the resources folder and put them somewhere else, re-saved them, everything aside from throwing them out.

EDIT: The file was saved as up.png but was really up.png.psd. just a matter of reading the fine print.


回答1:


Check the Kind in Finder. Its probably not a png and therefore wouldn't display.

I now know this to be true since you commented :)




回答2:


A couple of things. Select the file in the right pane, open the rightmost (3rd) file inspector pane, and insure that this image is included in your Target.

In code, break out this:

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


来源:https://stackoverflow.com/questions/12043589/uiimageview-image-not-showing-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!