Image unrecognized ios - ios

I have an UIImage that I assign to an UIImageView.
When I do :
UIImage *picto = [UIImage imageNamed:#"animage.png"];
UIImageView *imageView1 = [[UIImageView alloc] initWithImage:picto];
it works, but when I do :
UIImage *picto = [UIImage imageNamed:#"animage2.png"];
UIImageView *imageView1 = [[UIImageView alloc] initWithImage:picto];
My image 2 isn't displayed, the grammar is correct and my image exist in the project...
By the way, the second image is not displayed just because it name

use this format :
UIImageView *icon_bg=[[UIImageView alloc]init];
icon_bg.image=[UIImage imageNamed:#"animage.png"];
[Cell.contentView addSubview:icon_bg];

Related

how to make UIImage work in Xcode of Objective-c

I want to show a UIImage with following code:
UIImageView *image = [[UIImageView alloc ]initWithFrame:CGRectMake(0, 0, 500, 500)];
image.image = [UIImage imageNamed:#"1.png"];
[self.view addSubview:image];
And here is my Xcode config screenshot, just drag and drop the gifs folder into the Xcode with copy if necessary
try this.
image.image = [UIImage imageNamed:#"gifs/1.png"];
How to add image folders

Objective c: How to set the UIImageView image

hai iam new one for objective c and iOS development
Set the UIImageview image. try the following code
arrowImgVw is UIImageView Class object
UIImage *image=[[UIImage alloc]init];
image=[UIImage imageNamed:#"return_journey_denoter.png"];
arrowImgVw.image = image;
hey you are wrong in some point use this code for adding an image into UIImageView and display it on iPhone devide
UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
//Allocating imageView and set its frame.
myImage.image = [UIImage imageNamed:#"return_journey_denoter.png"];
//add image into imageview
[self.view addSubview:myImage];
// add imageview into your viewcontroller's view
To simply set image to imageView just one line of code
arrowImgVw.image = [UIImage imageNamed:#"return_journey_denoter.png"];
The code you have written is ok for setting image, just check the name for the given image or you can try following code...
UIIImageView *arrowImgVw = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,200,200)]; //just example change the frame as per your need
arrowImgVw.image = [UIImage imageNamed:#"return_journey_denoter"];
If you are trying to access the image from the assets . Use the below code
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
UIImage *image = [UIImage imageNamed:#"image" inBundle:bundle compatibleWithTraitCollection:nil];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
image should be inside your assets folder .
In Swift3.0
To set image to your imageView use belwo code.
arrowImgVw.image = UIImage(named: "return_journey_denoter.png")

How would I use a string of image names to use in a UIImageView?

I keep ending with an error saying that there are incompatible pointers assigning UIIMAGE to NSString.
self.imageNames = [NSArray arrayWithObjects:#"shop_deal.png",#"Date.png",#"Recreation.png",#"Productivity.png",nil];
UIImageView *imgView =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 150)];
imgView.image = [UIImage imageNamed:_imageNames];
[self addSubview:imgView];
I'm doing something wrong here...
In this line:
imgView.image = [UIImage imageNamed:_imageNames];
you have to use an NSString, not an entire NSArray. So try:
imgView.image = [UIImage imageNamed:[_imageNames objectAtIndex:0]];
instead.

Centering a UIImageView inside a UIScrollView

I am trying to center a UIImageView in a scroll view. Here is the code I tried with no results.
UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:kReceiptDetailScrollViewBackgroundCornered]];
[iv setContentMode:UIViewContentModeCenter];
[[self scrollView] insertSubview:iv atIndex:0];
Anybody know what's wrong with this?
You set the image view's content mode to center, which means that the image is not scaled and it can be larger than the image view that displays it.
UIImage *image = [UIImage imageNamed: kReceiptDetailScrollViewBackgroundCornered];
UIImageView *iv = [[UIImageView alloc] initWithImage: image];
iv.contentMode = UIViewContentModeScaleAspectFit;
iv.frame = [self scrollView].bounds;
[[self scrollView] addSubview: iv];

table view displaying image which is in project

i am trying to add image which i added in project i use following code for it
UIView *selectionView = [[UIView alloc] initWithFrame:CGRectMake(0, 7, 320, 50)];
[selectionView setBackgroundColor: [UIColor clearColor]];
UIImage *image = [[UIImage alloc]init];
image = [UIImage imageWithContentsOfFile:#"PlaceHolder.png"];
UIImageView* blockView = [[UIImageView alloc] initWithImage:image];
blockView.frame = CGRectMake(0, -5, 45, 45);
if([[[_arrayForTable valueForKey:#"URL"] objectAtIndex:[indexPath row]] isEqualToString:#"No Image"] )
{
[selectionView addSubview:blockView];
}
else
{
NSString *path = [[_arrayForTable valueForKey:#"URL"] objectAtIndex:[indexPath row]];
NSURL *url = [NSURL URLWithString:path];
AsyncImageView *imageView = [[[AsyncImageView alloc] init] autorelease];
imageView.frame = CGRectMake(0, -5, 45, 45);
imageView.imageURL=url;
[selectionView addSubview:imageView];
}
else condition work perfectly they have url of facebook to display images in table view but if condition in not working it going in to if condition but image is not getting displayed plz help
UIImage *image = [UIImage imageNamed:#"PlaceHolder.png"];
UIImageView* blockView = [[UIImageView alloc] initWithImage:image];
/*
imageNamed: is to load the picture which is in bundle. pass in the picture name
imageWithContentsOfFile: need to pass in the whole address of the file
*/
Try
UIImage *image = [UIImage imageNamed:#"yourfile.png"];
and add the image to the imageView and check the image file is aded to your project

Resources