有没有办法在AppDelegate中设置整个应用程序的默认背景图像,就像为导航栏设置默认背景一样?
示例:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navigation-bar.jpg"] forBarMetrics:UIBarMetricsDefault];
目前我在所有View控制器上都有此代码:
UIImage *backgroundImage = [UIImage imageNamed:@"bg.png"];
UIImageView *backgroundImageVIew = [[UIImageView alloc] initWithImage:backgroundImage];
self.myTable.backgroundView = backgroundImageVIew;
我在AppDelegate中试过这个:
UIImage *backgroundImage = [UIImage imageNamed:@"bg.png"];
UIImageView *backgroundImageVIew = [[UIImageView alloc] initWithImage:backgroundImage];
[[UITableView appearance] setBackgroundView:backgroundImageVIew];
它适用于所有视图,除了我所看到的视图。当我按下表视图单元格以转到另一个视图时,应用程序冻结,CPU上升到100%。
有什么建议吗?
答案 0 :(得分:0)
您可以创建UINavigationController的自定义子类,其中pushViewController方法看起来像
-(void) pushViewController:(UIViewController*) vc animated:(BOOL) animated
{
UIImage *backgroundImage = [UIImage imageNamed:@"bg.png"];
UIImageView *backgroundImageVIew = [[UIImageView alloc] initWithImage:backgroundImage];
vc.backgroundView = backgroundImageVIew;
[super pushViewController:vc animated:animated];
}
答案 1 :(得分:0)
使用AppDelegates didFinishLaunchingWithOptions
方法中的以下代码解决它:
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg.png"]];
imageView.frame = CGRectMake(imageView.frame.origin.x, 64.0, imageView.frame.size.width, imageView.frame.size.height);
[window addSubview:imageView];
Y帧中的值64.0用于推动状态栏和导航栏(20 + 44)正下方的imageView。