简体   繁体   English

在多个视图中使用背景图像到UINavigationController

[英]Use Background Image to UINavigationController among multiple views

How can I use a background image for UINavigationController, while maintaining the title? 如何在保持标题的同时为UINavigationController使用背景图像? The answer from ck on other thread did the trick to put the image and keep the text. 来自其他线程的ck的答案确实可以放置图像并保留文本。 But if the user navigates to other view ( using [navigationController pushViewController]), only the background appears in the new screen. 但是如果用户导航到其他视图(使用[navigationController pushViewController]),则只有背景出现在新屏幕中。

How can one change the background image for UINavigationController, while maintaining the title across multiple views? 如何更改UINavigationController的背景图像,同时在多个视图中保持标题?

And if you want to use ImageView to scale it : 如果您想使用ImageView来缩放它:

UIImageView *imageView = [[UIImageView alloc] initWithFrame:controller.view.bounds];
imageView.image = [UIImage imageNamed:@"aluminium-brushed-metal-background-texture-hd-575x400.jpg"];
imageView.contentMode = UIViewContentModeScaleAspectFill;
[navigationController.view insertSubview:imageView atIndex:0];

create a CustomUIViewController that extends UIViewController and override viewDidLoad to something like this: 创建一个CustomUIViewController,扩展UIViewController并覆盖viewDidLoad,如下所示:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]];
}

After that, use your CustomUIViewController in your controllers. 之后,在控制器中使用CustomUIViewController。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM