Reputation: 14383
There are some image resources in my Images.xcassets. Recently they cannot be displayed in the app when testing in the iPhone/iPad devices.
I guess they are not copied to the Bundle when build and package. Then i check the Copy Bundle Resources in Build Phases. The Images.xcassets is in here. One weird situation is it works well in simulators, but failed in the real devices. For a clean test, every time i will delete the app and then run again.
Some of snippets are as below:
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:@"[email protected]"] 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:@"[email protected]"] 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:@"[email protected]"] forState:UIControlStateNormal];
[button_Buy addTarget:self action:@selector(click_Buy) forControlEvents:UIControlEventTouchUpInside];
[imageview_ButtonBg addSubview:button_Buy];
images in the image set are as below:
Any help would be appreciated.
Upvotes: 1
Views: 2141
Reputation: 535139
The problem is that you have not understood the principle of asset catalogs. They give to their assets the names of the image sets. You no longer use the old size-based image names. That is the whole point of asset catalogs! You use one name and the right asset is chosen for you, appropriate to your hardware.
Thus, for example, this call is wrong:
[UIImage imageNamed:@"[email protected]"]
Your image set is called share_btnM, so you would say simply:
[UIImage imageNamed:@"share_btnM"]
You need to go through all your code, find all your imageNamed:
calls, and fix that everywhere. Then your images will work.
Upvotes: 2