Problem setting background image (GHWalkThrough library on github)

this is the open source github walkthrough library that I want to use in my application.

https://github.com/GnosisHub/GHWalkThrough

There is a way to configure the look of bg:

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

And I wanted to add many different images 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 image loads, there is a clear bg, and if I scroll left to index 1, I get screen 1>, and if I scroll left for indices 2, 3 and 4, bg will remain screen 1 ...

Can anyone see what is wrong here?

+5
source share
2 answers

I think you have a little code from the 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 cannot use the lower code and use the upper code, you get your result or the same as the lower code, and use the upper code, and then get the 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 the image name to the application folder as shown below.

(Note: your image name is listed below, as in your project.)

Example Image Name : -

enter image description here

Your condition is surprising that you received a new index, but do not receive the image, but when you specify the image name in the same way as the name of the top image, and you receive your images as an index.

+3
source

It seems you are not updating the index , which means that it stays at 0.

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

+1
source

All Articles