how to display images in imageview in iphone - iphone

Iam new to iphone currently my problem is
i displayed 6 images in 6 image views It was not showing images in imageview I think the imageviews are in large size
i implement code like this.
imageview1 = [[UIImageView alloc] init];
UIImage *img1 = [UIImage imageNamed:#"wolf.jpg"];
[imageview2 setImage:img1];
so plz send me correct code for this imageview.
Thank u in advance.

bgImage = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,480,300)];
bgImage.image = [UIImage imageNamed:#"Default.png"];
[self.view addSubview:bgImage];
Also check have you add image file to your project, by Add - > Existing File

First of all, you're adding the image 1 to imageview 2 - are you sure you want to do this?
Secondly, you need to add the imagview to the view hierarchy, for example by adding it to a ViewControllers view, like this: [[self view] addSubview:imageview1] (If this code is situated within the View Controller class).

imageview1 = [[UIImageView alloc] init];
imageview1.image = [UIImage imageNamed:#"wolf.jpg"];

Related

Unable to access UIImageView image

Currently attempting to access a UIImage property of UIImageView to instantiate another UIImage object. Simply I'm trying to do this.
UIImage *myImage = myExistingView.image;
The property will not set however. I keep getting nil values for myImage.
I would like to copy the image, eventually doing something like
UIImageView *newImageView = [[UIImageView alloc] initWithImage:myImage];
but I can't seem to get it down. Suggestions?
Edit. Most recent attempt that has not worked.
UIImageView *newView = [[UIImageView alloc] initWithImage:[[UIImage alloc] initWithData:UIImagePNGRepresentation(myImageView.image)]];
You have to Initialize your UIImage in this way UIImage *myImage = [UIImage imageNamed: #"imgCheckSelected.png"];
After you will pass myImage to newImageView. I`m not sure that you can save a UiImage inside another UIImage.
Do this for accessing images
UIImageView *newImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"imageName"]];
It will dispaly image.
I did this and it works..
UIImageView *someNewImageView = [[UIImageView alloc] initWithImage:yourExistingView.image];
someNewImageView.frame = CGRectMake(50, 50, 150, 150);
[self.view addSubview:someNewImageView];
[someNewImageView release];
Notice that yourExistingView is an UIImageView propertie added in Interface builder.
Have you checked the frame of your new UIImageView??
did you set the image in yourExistingView??
did you add the new imageview to view??

Display image in a UIImageView in iPhone

I do not wants use a picker view to pick a image. I have image name abc.JPG which is in iPhone image library, can I programmatically fetch this image and put on UIImageView?
If the image isn't in your application resource and you don't want to use UIImagePickerController then you can use ALAssetsLibrary to fetch the images on user albums or camera roll.
Take a look here:
http://developer.apple.com/library/ios/#documentation/AssetsLibrary/Reference/ALAssetsLibrary_Class/Reference/Reference.html
UIImageView *myImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
myImage.image = [UIImage imageNamed:#"abc.JPG"];
[self.view addSubview:myImage];
or if you have already uiimageview with name myImage then just write:
myImage.image = [UIImage imageNamed:#"abc.JPG"];
Maybe:
UIImageView *myImageView = [UIImageView alloc] init];
myImageView.image = [UIImage imageNamed:#"abc.JPG"];
Try to follow this tutorial.
Even if you don't want to, I think you have to use UIImagePickerViewController to pick the image, otherwise the image will be picked from Resources in your project.

Adding image to navigation bar of tab based application

I have tab base application
I want to add logo to the navigation bar I tried
(void)viewDidLoad {
[super viewDidLoad];
// add image
UIImage *image = [UIImage imageNamed:#"test.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
self.navigationItem.titleView = imageView;
}
but no image be displayed any suggestion to solve that
best regards
Try with setting frame of UIImageView *imageView ...
imageView.frame = CGRectMake(myX,myY,muWidth,myHeight)
Let me know if you still struggle ...
Do you have your leftBarButtonItem set? In the docs it says for titleView property of UINavigationItem: This property is ignored if leftBarButtonItem is not nil.

Adding backgroundimage to my app

I am using this code to add a background image to my tableview
myTable.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"background.png"]] autorelease];
on the internet they say this code works, but it's not working for me
can someone help me please?
if its a UITableViewController, as I believe it is, do this:
[myTable setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"background.png"]]];
or you can do (on a non-table view controller)
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"background.png"]]];
or on viewDidLoad you can do:
UIImageView *backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"background.png"]] autorelease];
[self.view addSubview:backgroundView];
but thats a bit messy - I prefer to use setBackgroundColor:
The problem is that backgroundview for tableview is a UIView, not a UIImage. So you need to create a view, easiest way is to use a UIImageView. For example this would put your splash screen image as the background view for the table in a UITableViewController...
UIImage *backImage = [UIImage imageNamed:#"default.png"];
UIImageView *backImageView = [[UIImageView alloc] initWithImage:backImage];
self.tableView.backgroundView = backImageView;
The methods mentioned above are pre the introduction of tableview property backgroundview in 3.2
edit - dear god I was obviously having a coffee deficit today :) The op is indeed using a UIImageView! The only thing I can think is that he is targeting a pre 3.2 platform...

UIImagePickerController bottom gets cut off when I add an overlay View

Need some help on an issue that is consuming my time. It's probably something really simple and I must be forgeting something. Here it go:
I have an UIImagePickerController in which I add a cameraOverlayView (just an ImageView). The problem is that the bottom bar gets cropped by some pixels. When I remove the overlay it works fine. I have even tried to change the overlay frame so that it fits the screen, the image is just the size of the camera viewport, but this happens even with small images. Here is some code:
UIImagePickerController* cam = [[UIImagePickerController alloc] init]; cam.sourceType = UIImagePickerControllerSourceTypeCamera;
cam.delegate = self;
UIImageView *overlay = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"silhueta.png"]];
overlay.frame = CGRectMake(0, 0, [UIImage imageNamed:#"silhueta.png"].size.width, [UIImage imageNamed:#"silhueta.png"].size.height);
cam.cameraOverlayView = overlay;
[overlay release];
Try to set the contentMode of your UIImageView to i.e. UIViewContentModeCenter.