Image is showing on simulator but not on a real iPhone - ios

So I got this piece of code, I want to show a picture on my view:
imgLogo = [[UIImageView alloc] init];
[imgLogo setFrame:CGRectMake(60, 200, 200, 200)];
[imgLogo setImage:[UIImage imageNamed:#"MyFrigginAwesomeLogo"]];
[self.view addSubview:imgLogo];
But the problem is that it works correctly when testing it on the simulator(iOS 7) but it doesn't show anything on my iPhone(4S with iOS7) itself.

Answer added from Comment:
The iOS devices are case sensitive, but the simulator is not. Make sure you are trying to load the exact filename in order for them to be found.

Try using the designated initializer for UIImageView instead of just init:
NSString *logoName = #"MyFriggingAwesomeLogo";
imgLogo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:logoName]];
imgLogo.frame = CGRectOffset(imgLogo.frame, 60, 200);
[self.view addSubview:imgLogo];
It's also possible that you've added the image resource to only the simulator target. In your bundle settings Build Phases, make sure you have the image listed in Copy Bundle Resources.

Related

Since the last Xcode update I can't work with images

This is the basic code I use to add an image named "Background.png" to an UIImageView:
UIImageView *imageView = [[UIImageView alloc] init];
imageView.image = [UIImage imageNamed:#"Background.png"];
imageView.frame = CGRectMake(0.0, 0.0, self.view.frame.size.width, self.view.frame.size.height);
[self.view addSubview:imageView];
Since the last Xcode update the resource can't be loaded.
I tried running on an iPhone 6 - iOS 10.3 and the Simulator - iOS 11.0
For some reason even though the iOS deployment target is version 10.3 the simulator runs on iOS 11.0
The image is there, in the same folder as the project named: "Background.png"
I've been doing the same thing for years and now it has stoped working.
Anyone had a similar issue?
You may want to utilize the purpose of Assets.xcassets. Put your assets there and you can easily use your images. Note that you do not have to put the image's file extension. It's easy, like so:
UIImage *markerImage = [UIImage imageNamed:#"marker"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:markerImage];
[imageView setFrame:CGRectMake(0, 0, 100, 100)];
[self.view addSubview:imageView];
I have an image in my Assets.xcassets named marker.
Edit: this is tested, I made an Objective-c project just for this question :)
I had the same problem and i solved it as follow:
Simply Select your image, then check the box linked to your projet name in "Target Membership" (on the Right Window)
is it working ?
There is a Screenshot if needed:
https://i.stack.imgur.com/gTOGJ.png

FoxitIOSRDK: not able to click on Hyperlink

I am using FoxitRDK framework for opening the pdf document in my App. In the demo everything works fine apart from one thing: I am not able to click on hyperlink. I have go through the SDK document and the classes inside framework but can not able to fine the solution.
The document link is below:
http://www.foxitsdk.com/docs/mobile-pdf-sdk/developer_guide_ios.pdf
and here is my code
NSString* pdfPath = [[NSBundle mainBundle] pathForResource:#"getting_started_ios1" ofType:#"pdf"];
// Initialize a PDFDoc object with the path to the PDF file
FSPDFDoc* pdfdoc = [FSPDFDoc createFromFilePath:pdfPath];
// Initialize a FSPDFViewCtrl object with the size of the entire screen
pdfViewCtrl = [[FSPDFViewCtrl alloc] initWithFrame: CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-60)];
[pdfViewCtrl registerDocEventListener:self];
[pdfViewCtrl registerPageEventListener:self];
[pdfViewCtrl registerGestureEventListener:self];
// Set the document to display
[pdfViewCtrl setDoc:pdfdoc];
// Add the pdfViewCtrl to the root view
[self.view addSubview:pdfViewCtrl];
extensionsManager= [[UIExtensionsManager alloc]initWithPDFViewControl:pdfViewCtrl];
pdfViewCtrl.extensionsManager = extensionsManager;
[extensionsManager registerAnnotEventListener:self];
[extensionsManager registerAnnotHandler:self];
//Search button
searchButton = [[UIButton alloc] initWithFrame:CGRectMake(280, 80, 80, 40)];
[searchButton setBackgroundColor:[UIColor grayColor]];
[searchButton setTitle: #"Search" forState: UIControlStateNormal];
[searchButton addTarget:self action:#selector(showSearchBar)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:searchButton];
How can I fix this?
You need to added UI extensions component to your app.
you can refer to the step in section"2.4.5 Add support for Text Search, Bookmark, and Annotation" of the developer guide.
After added the UI extensions to you project, and Initialize it, the link will be work.
related code are here:
"#import "../uiextensions/UIExtensionsManager.h"
UIExtensionsManager* extensionsManager;
...
extensionsManager = [[UIExtensionsManager alloc] initWithPDFViewControl:pdfViewCtrl];
pdfViewCtrl.extensionsManager = extensionsManager;"
If you want to Goto special page when a document open, you need to do it in the onDocOpened event.
(void)onDocOpened:(FSPDFDoc*)document error:(int)error
{
[_pdfViewCtrl gotoPage:2 animated:false];
}
Thanks Foxit support team after updating the version to 2.0 it works perfect.
I have got the solution.
Good luck Team.

Changing CurrentPositionView in Skobbler/skmaps not working

I wanted to change to default current position marker of skmaps.
I have tried this:
self.mapView.currentPositionView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"nui-img-car"]];
But this is not working. It is still showing default position marker.
And advice please.
I tried the following in the demo project and it worked flawlessly:
self.mapView.currentPositionView = [[UIImageView alloc]
initWithImage:[UIImage imageNamed:#"picture"]];
picture.png is in the /Resources folder

Image missing from distribution

I am having an issue where an image is missing, but only when built for distribution. Also, it only occurs on the iPhone 5, but not for the iPhone 4 or 4S.
This is a screenshot when built for development, on the simulator.
And this is a screenshot when built for distribution, on an actual iPhone 5.
I have a single target for both development and distribution. Relevant code:
int deviceNumber = 4;
if([UIScreen mainScreen].bounds.size.height > 500)
deviceNumber = 5;
MYIntroductionView *introductionView = [[MYIntroductionView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.bounds.size.width, self.view.bounds.size.height) panels:#[panel1,panel2,panel3]];
if(deviceNumber == 4){
[introductionView setBackgroundImage:[UIImage imageNamed:#"One Degree_Iphone4_Background.png"]];
}
else{
[introductionView setBackgroundImage:[UIImage imageNamed:#"One Degree_Iphone5_Background.png"]];
}
And within MyIntroductionView.m, the relevant code is:
-(void)setBackgroundImage:(UIImage *)backgroundImage{
self.BackgroundImageView.image = backgroundImage;
}
-(void)buildBackgroundImage{
self.BackgroundImageView = [[UIImageView alloc] initWithFrame:self.frame];
self.BackgroundImageView.backgroundColor = [UIColor clearColor];
self.BackgroundImageView.contentMode = UIViewContentModeScaleToFill;
self.BackgroundImageView.autoresizesSubviews = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self addSubview:self.BackgroundImageView];
}
buildBackgroundImage is called within the init function.
I'm not 100% sure this is still the case but I know it used to be:
The iOS Simulator is not case-sensitive with regard to external filenames (such as your images). So if the image is named "myImage.png" and your program asks for "MyImage.png", the simulator will correctly find and load the image.
However when you try and run it on the device, it is case sensitive, and will not accept the incorrectly-cased file.
So double check that your capitalization of the file itself is identical to what you're asking for in your program. Hopefully that will fix your issue right up.

UIImageView image not showing up

_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.
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 :)
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

Resources