How to display photos on URL into UICollectionView also make paging for photos , any help please
NSString *MyPatternString=[self.PatternImages objectAtIndex:indexPath.row];
cell.PattImagCollection.image=[UIImage imageNamed:MyPatternString ];
You can try this:
UIImage *image = [UIImage imageWithData:[NSData
dataWithContentsOfURL:[NSURL URLWithString:YourURL]]];
cell.yourimageviewname.image = image;
Related
This question already has answers here:
Getting Image from URL Objective C
(5 answers)
Closed 4 years ago.
I am trying to fetch images from URL and displaying it on collection view how to do it ?
I have used following code but didnt get answer
(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
collectionGalleryTechrCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
// NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString:Url];
//UIImage *image = [UIImage imageWithData:imageData];
//CollectionViewImage.image = image;
NSURL *urlBack = [NSURL URLWithString:#"http://ssk.com/zpschool1/web/gallery/download%20(4).jpg"];
NSData *urlDataBack = [NSData dataWithContentsOfURL:urlBack];
UIImage *imageBack = [UIImage imageWithData:urlDataBack];
cell.myImg.image =imageBack;
//cell.myImg.image = [UIImage imageWithData:ImgURL];
cell.myImg.userInteractionEnabled=YES;
return cell;
}
Loading and displaying image asynchronously is better then getting NSData from URL and displaying imageWithData in UICollectionView or UITableView.
You can check out this answer given in the link below :
https://stackoverflow.com/a/34041518/9332509
NSString *strImg_Path = [[NSString alloc]init];
strImg_Path = [NSString stringWithFormat:#"%#",[NSURL URLWithString:#"http://ssk.com/zpschool1/web/gallery/download%20(4).jpg"];
];
[cell.myImg sd_setImageWithURL:[NSURL URLWithString:strImg_Path]
placeholderImage:[UIImage imageNamed:#"placeholer_image"]];
make sure placeholer_image for default image and use framework - SDWebImage for lazy loading.
Use Url from your array for dynamic instead of static Url.
NSString *img=[arrImages objectAtIndex:i];
imgScrollView.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:img]]];
I have displayed my code. The URL links have been stored into an array and the images are also fetching into uiimage view, but only the first two images are loaded into the imageview while the others didn't load .
arrImages:
inside image viewhttp://localhost:8888/welcome/company/0/images/TV Repair.png
this is the link present in the arrImages i don't know why first two images has been loading.
FOR LOOP:
for(NSDictionary *DicHoleCategories in ArrCategory)
{
StrName=[DicHoleCategories objectForKey:#"image"];
if(StrName!=nil)
{
subimages=[NSString stringWithFormat:LocalImage"%#",StrName];
[DicAllValues setObject:subimages forKey:#"image"];
NSError *error =nil;
}
[arrImages addObject:[DicAllValues objectForKey:#"image"]];
}
Can anyone find the issue and help me please?
Go through the below coding
//url string
NSString *ImageURL = #"yoururl";
//string to data conversion
NSData *imagedata = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURL]];
//set image
imageView.image = [UIImage imageWithData:imageData];
please follow the below code
if(StrName!=nil)
{
subimages=[NSString stringWithFormat:LocalImage"%#",StrName];
[DicAllValues setObject:subimages forKey:#"image"];
NSError *error =nil;
[arrImages addObject:[DicAllValues objectForKey:#"image"]];//add here!
}
Plz check now and tell me if its working or not!
How to display an Image in the ImageView which is fetched from the WebService?
I am able to retrieve the Name of the image from the service successfully, but unable to set the image in the ImageView
NSString *imgName = [students objectForKey:#"Image"];
NSLog(#"%#", imgName); **/* Image1.png */**
imgImage.image = [UIImage imageNamed:imgName];
NSLog gives following output on Console :
Image1.png
I am unable to set the image in the ImageView
You can use the SDWebImage :
// Here we use the new provided setImageWithURL: method to load the web image
[cell.imageView setImageWithURL:[NSURL URLWithString:#"http://www.domain.com/path/to/image.jpg"]
placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
This is the link for download and how to use it:
https://github.com/rs/SDWebImage
You can also use this code set image
cell.img.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:#"your url"]]]];
http://www.imageurlhost.com/viewer.php?is_random=1&file=9psik7w1j5rkef8kek5.jpg
or
image code - 1wba395mv72m3of2ikz.jpg
i used this.
NSURL *imageURL = [NSURL URLWithString:#"http://www.imageurlhost.com/viewer.php?file=1wba395mv72m3of2ikz.jpg"];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage *image = [UIImage imageWithData:imageData];
UIImageView *imgview1 =[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 150,150 )];
imgview1.image= image;
[scrlview addSubview:imgview1];
you can set the image in image view like this
[imageView setImageWithURL:[NSURL URLWithString:#"your url string"] placeholderImage:[UIImage imageNamed:#"Placeholder.png"]];
placeholder.png is any temporary image which is replaced when image from url is received
Rahul paliwal ...Your url is html page..if you want load image in imageview use proper url...
if u want load image in imagview...like
this...
NSURL *url = [NSURL URLWithString:
pictureUrl];
UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]];
NSLog(#"image width:%#",image.size.width);
I am getting null from this log? The image is valid and displaying correctly?.
This is in a table cell
Try this:
NSLog(#"image width:%f",image.size.width);
Besides that, I hope you are calling this on a background thread (not within cellForRow), otherwise loading your cells will be very slow and screw up user interaction.