Use Background Image to UINavigationController among multiple views

。_饼干妹妹 提交于 2019-12-22 13:56:49

问题


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


来源:https://stackoverflow.com/questions/5768443/use-background-image-to-uinavigationcontroller-among-multiple-views

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!