Use Background Image to UINavigationController amo

2019-05-27 10:29发布

问题:

How can I use a background image for UINavigationController, while maintaining the title? The answer from ck on other thread did the trick to put the image and keep the text. But if the user navigates to other view ( using [navigationController pushViewController]), only the background appears in the new screen.

How can one change the background image for UINavigationController, while maintaining the title across multiple views?

回答1:

create a CustomUIViewController that extends UIViewController and override viewDidLoad to something like this:

- (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.



回答2:

And if you want to use ImageView to scale it :

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];