Ios 背景图像设置问题(github上的GHWalkThrough库)
这是github上的一个演练开放库,我想在我的应用程序中使用它 有一种方法可以设置bg视图:Ios 背景图像设置问题(github上的GHWalkThrough库),ios,objective-c,Ios,Objective C,这是github上的一个演练开放库,我想在我的应用程序中使用它 有一种方法可以设置bg视图: - (UIImage*) bgImageforPage:(NSInteger)index { UIImage* image = [UIImage imageNamed:@"bgimage"]; return image; } 我想为每个索引添加一组不同的图像,所以我这样做了: - (UIImage*) bgImageforPage:(NSInteger)index { UI
- (UIImage*) bgImageforPage:(NSInteger)index
{
UIImage* image = [UIImage imageNamed:@"bgimage"];
return image;
}
我想为每个索引添加一组不同的图像,所以我这样做了:
- (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;
}
结果:
无论何时加载视图,都会有一个清晰的背景,如果我向左滑动到索引1,就会得到屏幕1>,如果我向左滑动到索引2、3和4,背景会保持在屏幕1
有人能看到这里出了什么问题吗?您似乎没有更新
索引,这意味着它保持在0
如果它保持在0,图像将始终是“屏幕1”
我认为您的代码有轻微错误
- (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;
}
如果您不能使用底部代码和使用上部代码,那么您得到的结果与使用底部代码和使用上部代码相同,那么您也会得到相同的结果
- (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;
}
请在应用程序图像文件夹中添加图像名称,如下所示
(注意:您的图像名称设置如下,与您的项目相同)。
示例图像名称:-
根据您的条件,您获得了新的索引,但没有获得图像,但当您将图像名称设置为与upper images name相同时,您将图像设置为index wise。您是否尝试过在该方法中设置断点,并找出您收到的索引值?提供的所有图片是否确实存在于您的图像资产中?此代码-(UIImage*)bgImageforPage:(NSInteger)索引{UIImage*图像=[UIImage ImageName:@“screen 1”];返回图像;}使用单幅图像效果很好?它是一种委托方法,在页面滑动时为我提供索引,这意味着在页面滑动时索引没有正确更新。好的,因此我想根据我共享的代码获得一些代码示例:)请帮助我,它让我发疯。还有为什么第一张bg图像也是清晰的?我应该在哪里设置它,因为只有在我刷卡时才会调用委托方法…当我加载应用程序时,首先要看到的是演练