Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 778
nick shmick Avatar asked Oct 20 '22 04:10

nick shmick


1 Answers

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.

like image 77
Sandy Patel Avatar answered Nov 11 '22 17:11

Sandy Patel