简体   繁体   中英

how to change url image in UIImage View on xcode with Next , Back button?

I want create one page in my application that have 2 button (1.back button 2.next button) these buttons change image in UIImageView.(all Images load from my site and them format is 1.png , 2.png , 3.png ,.... , N.png)

I don't know how to work when click next button(back button) show images one after another(one before another)

The idea is to read the basics of animation (or core animation) in iOS.

You should probably read the following guide: View Programming Guide in iOS

Moreover, the idea is to have a button with an action that displays a view and checks if there is an imageView that's already displayed on the screen. If it's not displayed, you display the required imageView. If it's displayed, you remove the view using:

[someImageView removeFromSubview:yourMainView]

which may be called in the same viewController. The login would be depend on the way you handle buttons and imageViews.

I don't have Xcode on this machine to check but this is how things will proceed. You may then add animations to remove and add those views.

You have to fill Array with images names and do following

-(IBAction) nextButtonClicked:(id)sender {
    if (counter < images.count) {
        self.imgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@", images[counter]]]
        counter++;
    } else {
        counter = 0;
    }
}

-(IBAction) backButtonClicked:(id)sender {
    if (counter > 0) {
        counter--;
        self.imgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@", images[counter]]]
    } else {
        counter = [images.lastObject intValue];
    }
}

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