In my application I have used Lazyloading for displaying image from url. But now i want to display two multiple images in one cell. How can i do this please help me.
Maybe this will help you. add this code in cellfor row and for Download Image use SDWebImage
UIImageView *imgView1=[[UIImageView alloc]init];
imgView1.frame=CGRectMake(0,0,20,20);//Your Frame
imgView1.image = [UIImage ImageNamed:#"a"]; // your image or download image code or use Sdwebimage
[cell.contentView addSubview:imgView1];
UIImageView *imgView2=[[UIImageView alloc]init];
imgView2.frame=CGRectMake(25,0,25,25);//Your Frame
imgView2.image = [UIImage ImageNamed:#"b"]; // your image or download image code or use Sdwebimage
[cell.contentView addSubview:imgView2];
If you want to add more images then add same code and just give frame.
Related
I like to implement image upload functionality in my app.For that I like to give some option for user to choose image.
One of the option is choose image from website.
If the user enter an url link in the text box and click the get images button means. I like to display all the images in that particular link
But I am not having any idea about this.
I have explain my requirement below
1)Enter the url in a text box
2)Click the get images button
3)Parse all the images from that particular url
4)Display all the images in the Imageview
And also to illustrate my requirement I have attached the screenshot below
If anybody work around this functionality means please suggest me some idea
Thanks
Like this ?
- (IBAction)buttonClicked:(id)sender
{
NSURL *url = [NSURL URLWithString:#"http://www.yourwebvsite.com/image.png"];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData: data];
UIImageView *displayImageView = [[UIImageView alloc] initWithImage:image];
[displayImageView setFrame:CGRectMake(0, 0, 300, 300)];
[displayImageView setContentMode:UIViewContentModeScaleAspectFit];
[self.view addSubview:displayImageView];
}
Or if you want all the images from a web directory. See here and save all the images in an array then display the images in a UIImageView like my code above.
Suppose I generated the 100 image views. First of all I wish to generate all 100 image views and add them in my scroll view.
So image view are clearly display it’s in position using background color
Then after I want to set images into the image view. I have to types of Dictionary (Which comes from the another class). One Dictionary into set Already Downloaded images and another one into only generate object (Remaining download images). I am downloading this image Asynchronously.
Then how can I set images into the image view?
-(void)GenerateImageView{
for (int ivalue = 0; ivalue < 100; ivalue++) {
imageView = [[UIImageView alloc] init];
//Give tag to the image view
imageView.tag = ivalue;
[imageView setBackgroundColor:[UIColor whiteColor]];
CGFloat xOrigin =ivalue *ascrollView.frame.size.width+50;
imageView.frame=CGRectMake(xOrigin40,imgYpos,ascrollView.frame.size.width-20, scrollViewHight);
//set imageview into the scroll view
[ascrollView addSubview:imageView];
}
}
Then how can I set images into the imageview?
UIImageView *imageView = [ascrollView viewWithTag:some_tag];
if ([imageView isKindOfClass:[UIImageView Class]])
imageView.image = your_UIImage_object;
u can not access the directly image view.And also make sure ur tag not start with 0.bcs 0 is a by default main view tag
imageView = (UIImageView *)[ascrollView viewWithTag:some_tag];
imageView.image = your_UIImage_object;
You could use the code Avt suggested, but instead of reinventing the wheel, I would suggest to look into
AFNetworking
an open-source networking lib. It comes with an extension to the UIImageView which allows you to load the images asynchronously out-of-the-box. There are many other useful features too.
After importing the extension you could then use:
[imageView setImageWithURL:[NSURL URLWithString:#"yourImageURL"]];
the image gets loaded asynchronously and automaticly set when it's done loading.
I am setting images to a UIImage programmatically. But I want to also add a play button over that view. Think of Facebook in how there is a play button over the image. That is exactly what I am trying to figure out on what to do. Here is my setting of the UIImage:
UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:#"%d.jpg", indexPath.row]];
cell.photoView.image = img;
Suggestions, thoughts?
You can add playbutton either as a UIButton or a UIImageView and add as a subview to your photoview.
[cell.photoView addSubview:urPlayButtonView];
How to add animated gif file as a default image for UIButton.
I have added gif file as button image. But it is not animating.
Thanks.
Animated GIF won't animate in iphone.. You should add a UIImageView as subview to UIButton, extract all images from your GIF and animate using UIImageView Animation
UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
animatedImageView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"image1.gif"],
[UIImage imageNamed:#"image2.gif"],
[UIImage imageNamed:#"image3.gif"],
[UIImage imageNamed:#"image4.gif"], nil];
animatedImageView.animationDuration = 1.0f;
animatedImageView.animationRepeatCount = 0;
[animatedImageView startAnimating];
[yourButton addSubview: animatedImageView];
You can not just load a gif file. Save every frame of the gif to a separate image file (png or similar) - you can do that with photoshop for example, then load them into a UIImage using animationImages and do a startAnimating.
In iOS .gif file format is not supported. so avoid using .gif files in iOS
You should explore alternatives to using UIButton for that, since it does not allow for such customization. E.g., you could use UIImageView` for your button and set an action for the "touch end" event.
I have loaded the image in application's folder that is source
but I could not find the code by which I will display that image
on UIImageView using button click event. Please help me out for this.
I have used this following code before:
UIImage *img = [UIImage imageNamed:#"xyz.png"]
but I could not set the UIImageView image to img in the method
Then please help me with code to set the UIImageView image to img in the method I call on my button click.
You can get an image added to your project folder/subfolder using
UIImage *img = [UIImage imageNamed:#"xyz.png"]
Then set the UIImageView image to img in the method you call on your button click.
Drag the image into Xcode and then set up an UIImage variable like this:
UIImage *theImage = [UIImage imageNamed:#"theImage.png"];
then implement it into your UIImage view by 'myImageView.image = theImage;
Make sure you have IBOutlet set up to your image view, though. The easiest way is to just drag the image into Xcode and select it under the popup list in Interface Builder.