简体   繁体   中英

how to display image in UIImageView in a specifc block of window in iphone

I have a window in which I want to display an image in a specific block of that window. The image is retrieved from the local XML file. I parsed the XML file and got the image value in the log, but I don't know how to put it in that specific block. The below image pasted for the reference.

UIImageView

The arrow mark represents that within this UIImageView I need to get the image. Also, I doubt that I need to mention any name for reference to UIIMageView in storyboard. Suggest me an idea.

Edited

My parser code:

NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Sample.xml"];
NSData *data = [[NSData alloc] initWithContentsOfFile:path];
 NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithData:data];
[xmlParser setDelegate:theParser]

After this I am using this code for getting image:

UIImage *image = [UIImage imageWithContentsOfFile:@"/Users/administrator/Desktop/imageApp/resources/Main_pic1.png"];

After this I don't know how to continue.

Yes, you have to create IBOutlet in .h file

like IBOutlet UIImageView *imgview; and connect imgview with your UIImageview from xib.

After that you can set image to image view.

NSURL *URL = [NSURL URLWithString:[your url which u get form local xml]];
NSData *imageData = [NSData dataWithContentsOfURL:URL];
UIImage *image = [UIImage imageWithData:imageData];

imgview.image=image;

Ttry this, It may help you.

You can directly pass the url image to Uiimageview by :

YourImageView.image = [UIImage imageWithContentsOfURL:YourUrl];

It's possible to do the equivalent by going through NSData, but it's a bad idea. Instead, the image should be downloaded asynchronously using NSURLConnection, and only once it's fully downloaded should it be converted into a UIImage and assigned to the image view.

Save all your urls in an say NSMutableArry *UrlArray then

int x = 0;
int y = 10;

for (int i = 0; i< [UrlArray]; i++)
{
    UIImageView *imageView = [[[UIImageView alloc]initWithFrame:CGRectMake(3+x,y, 80,
    80)]autorelease];
    imageView.backgroundColor = [UIColor blueColor];
    if (x >= 300)
    {
        x = 0;

        y = y+imageView.frame.size.height+3;
        imageView.frame = CGRectMake(x+3 , y, 80, 80);

    }


     CIImage *beginImage = [CIImage imageWithContentsOfURL:[UrlArray ObjectAtIndex:i]];
    imageView.image = [UIImage imageWithCIImage:beginImage];
    x = x+imageView.frame.size.width+5;
    [self.view addSubview:imageView];

}

will do the work i guess;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM