I used MMScrollPresenter for 4 images. It is perfectly done. But now i want to used this for dynamic, how can i done. I know this can be done using for loop.
NSArray *array = [[NSArray alloc]initWithObjects:#"mountains.jpg",#"forest.jpg", nil];
for(int i=0;i<array.count;i++)
{
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:#"%#",array[i]]]];
[imageView setFrame:CGRectMake(0, 0, scrollImg.frame.size.width, scrollImg.frame.size.height)];
Page = [[MMScrollPage alloc] init];
[Page.backgroundView addSubview:imageView];
}
[scrollImg addMMScrollPageArray:#[Page]];
After using this code, scroll view not working. Anybody can help me.
Related
I have a images sequence animated with :
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 120)];
[UIImage animatedImageNamed:#"spinner-" duration:1.0f];
imgView.contentMode = UIViewContentModeCenter;
imgView.animationRepeatCount = 1; // No effect
[self.view addSubView:imgView];
But the sequence keeps looping. Is there a way to control the repeat count (and keep displaying the last image) ?
In your case, using [UIImage animatedImageNamed:#"spinner-" duration:1.0f]; won't give you what you want.
For what you would like to achieve, I would recommend using UIImageView.
Usage:
First create an UIImageView object:
UIImageView *imageView = [[UIImageView alloc] initWithFrame:<FRAME_SIZE>];
Second, create an array that holds your images to be animated.
If you just have a few, do the following:
NSMutableArray *animatedImagesArray = [[NSMutableArray alloc] initWithObjects:[UIImage imageNamed:#"spinner-1.png"], [UIImage imageNamed:#"spinner-2.png"], nil];
If you have more, then you could load your images into the array like this:
for (int i = 0; i < <NUM_OF_IMAGE_COUNT>; i++)
{
[animatedImagesArray addObject:[UIImage imageNamed:[NSString stringWithFormat:#"spinner-%d%#", i, #".png"]]];
}
Once all that is done, then we configure the controls you want:
imageView.animationImages = animatedImagesArray;
imageView.animationDuration = 1.0f;
imageView.animationRepeatCount = 1.0f;
Then start animating it by:
[imageView startAnimating];
And stop the animation via:
[imageView stopAnimating];
If you would like the UIImageView to hold the last image after stopping, we would need to carry out the following before starting the animation:
imageView.image = [imageView.animationImages lastObject];
....
[imageView startAnimating];
Hope this helps.
You set the repeat count in the UIImageView object that displays your image.
UIImage *testImage = [UIImage animatedImageNamed:#"Box.jpg" duration:1.0f];
UIImageView *imgView = [[UIImageView alloc] initWithImage:testImage];
[imgView setAnimationRepeatCount:1];
I am creating several UIView's which I add a UITapGestureRecognizer with an action thats suppose to call a method in the viewController, but it doesn't seem to work.
-(void)setupFreeMoneyView {
NSArray *array = #[#"Facebook", #"Twitter", #"SMS", #"Email"];
int index = 0;
for (NSString *str in array) {
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(100*index++, 0, 100, 100)];
[imgView setImage:[UIImage imageNamed:[NSString stringWithFormat:#"%#Logo", str]]];
[imgView addGestureRecognizer:[[UITapGestureRecognizer alloc]
initWithTarget:self
action:NSSelectorFromString([NSString stringWithFormat:#"postTo%#", str])]];
[freeView addSubview:imgView];
}
}
freeView is a UIView created in the MainStoryboard.
Ive checked if its the NSSelectorFromString() by using a normal #selector() thats not working but it isn't the cause.
It does work if I change the line [imgView addGestureRecognizer:... to [freeView addGestureRecognizer:...]
I just don't seem to understand why this is happening.
try this
imgView.userInteractionEnabled = YES ;
userInteractionEnabled of UIImageView is set to NO by default.
maybe you need set userInteractionEnabled = YES for the UIImageView
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
I am rather new to Cocoa programming and need some help.
I want to make some image views for units in a game and add them with code, because to put them in the view and make conections in Interface Builder is a lot of work.
I already have found code to create and insert UIImageViews:
UIImageView *image0 =[[UIImageView alloc] initWithFrame:CGRecMake(x,y,w,h)];
image0.image=[UIImage imageNamed:#"image.png"];
[self.view addSubview:image0];
My question is: if I can make an array, then I don't have to write this for every image view, and I put the same image in it?
A nice way to do it would be something like this. This will create 30 image views with the same image.
NSMutableArray *arrayOfImageViews = [NSMutableArray array];
for (int i = 0; i < 30; i++) {
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"theImage.png"]];
[self.view addSubview:imageView];
[arrayOfImageViews addObject:imageView];
}
How about this:
for(int i=0; i<10; ++i) {
UIImageView *image =[[UIImageView alloc] initWithFrame:CGRecMake(x+i*k1,y*i*k2,w,h)];
image.image=[UIImage imageNamed:#"image.png"];
image.tag = i+1;
[self.view addSubview:image0];
}
I'm trying to create an animated UIImageView with certain image constraints.
I want the UIImageView animating at a size of 141x262, and not the entire screen. Currently I have this code:
CJ = [[UIImageView alloc] initWithFrame:self.view.frame];
CJ.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"CJ_1.png"],
[UIImage imageNamed:#"CJ_2.png"],
[UIImage imageNamed:#"CJ_3.png"], nil];
CJ.animationDuration = 1;
CJ.animationRepeatCount = 0;
[CJ startAnimating];
[self.view addSubview:CJ];
Any and all help will be appreciated!
If you want the view to be a different size, set its frame to be that size:
CJ = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 141, 162)];
If your images are large, you probably also want to set a contentMode on your view. For example:
CJ.contentMode = UIViewContentModeScaleAspectFit;