nick shmick
nick shmick

Reputation: 925

Background Image setup issue (GHWalkThrough library on github)

this is a walkthrough open library on github that I want to use in my app.

https://github.com/GnosisHub/GHWalkThrough

there is a method to set up bg view:

- (UIImage*) bgImageforPage:(NSInteger)index
{
    UIImage* image = [UIImage imageNamed:@"bgimage"];
    return image;
}

And I wanted to add set different image for each index, so i did this:

- (UIImage*) bgImageforPage:(NSInteger)index {

    UIImage* image;

    if (index == 0) {
        image = [UIImage imageNamed:@"screen 1"];
    } else if (index == 1) {
        image = [UIImage imageNamed:@"screen 2"];
    } else if (index == 2) {
        image = [UIImage imageNamed:@"screen 3"];
    } else if (index == 3) {
        image = [UIImage imageNamed:@"screen 4"];
    }

    return image;
}

Result:

whenever the view is loaded there is a clear bg, and if I swipe left to index 1 I get screen 1 > and if I swipe left for index 2, 3 & 4 the bg stays screen 1...

Can someone see what is wrong here?

Upvotes: 5

Views: 135

Answers (2)

Sandy Patel
Sandy Patel

Reputation: 768

i think you have minor mistak from code.

- (UIImage*) bgImageforPage:(NSInteger)index
{     
    NSString* imageName =[NSString stringWithFormat:@"bg_0%ld.jpg", index+1]; // you have manually add name but not increment index
    UIImage* image = [UIImage imageNamed:imageName];
    return image;
}

if you can't use bottom code & use upper code you got your result or same as use bottom code & use upper code then also you got same result.

- (UIImage*) bgImageforPage:(NSInteger)index
{

    NSString* imageName =[NSString stringWithFormat:@"bg_0%ld.jpg", index+1];
    UIImage* image;// = [UIImage imageNamed:imageName];
    if (index == 0) {
        image = [UIImage imageNamed:imageName];
    } else if (index == 1) {
        image = [UIImage imageNamed:imageName];
    } else if (index == 2) {
        image = [UIImage imageNamed:imageName];
    } else if (index == 3) {
        image = [UIImage imageNamed:imageName];
    }


    return image;
}

Please add image name in your app image folder like below.

(Note: your image name set below as in your project.)

Example Image Name :-

enter image description here

your condition wise you got new index but not getting images but when you set images name like same as upper images name & you got your images as index wise.

Upvotes: 2

VonC
VonC

Reputation: 1329122

You don't seem to update index, which means it stays at 0.

If it stays at 0, the image will always be "screen 1".

Upvotes: 1

Related Questions