横向模式下UINavigationBar的自定义背景 [英] Custom background for UINavigationBar in landscape mode
问题描述
我正在为我的UINavigationBar添加自定义背景。只要手机处于纵向模式,它就可以正常工作。一旦我切换到横向模式,一半的条形显示为蓝色(默认的导航栏颜色),其中一半有我的图像
I am adding a custom background for my UINavigationBar. It works fine as long as the phone is in portrait mode. As soon as I switch to landscape mode, half the bar appears blue (the default navbar color) and half of it has my image
如何拉伸图像以获得横向模式并在肖像模式下再次缩小?
How can I stretch the image for landscape mode and make it small again for portrait mode?
谢谢
解决方案
如果有人正在寻找如何将图像添加到导航栏的答案 - 这里是
Solution
Incase anyone is looking for an answer to how to add an image to navigation bar - here goes
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 480.0, 44.0)];
[imgView setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"navbar_landscape" ofType:@"png"]]];
[navigationController.navigationBar addSubview:imgView];
[imgView release];
推荐答案
您可能需要设置背景图像的autoresizingMask视图;尝试使用 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight
You probably need to set the autoresizingMask of your background image view; try using UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight
这篇关于横向模式下UINavigationBar的自定义背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!