简体   繁体   English

图片中的UINavigationBar背景

[英]UINavigationBar background from an image

I have an image of width x height = 1 x 44 that I want to transform on the x horizontal for the purpose of generating a background for my nav bar. 我有一张宽度x高度= 1 x 44的图像,我想在x水平方向上进行转换,以便为导航栏生成背景。 How do I do this? 我该怎么做呢?

Does this link help: http://sebastiancelis.com/2009/12/21/adding-background-image-uinavigationbar/ 该链接是否有帮助: http : //sebastiancelis.com/2009/12/21/adding-background-image-uinavigationbar/

"As of iOS 5, Apple has officially added support for setting background images in UINavigationBars. To do this, all you need to do is execute the setBackgroundImage:forBarMetrics: method of UINavigationBar." “从iOS 5开始,Apple正式添加了对在UINavigationBars中设置背景图像的支持。为此,您要做的就是执行UINavigationBar的setBackgroundImage:forBarMetrics:方法。”

try this in the viewController.m file viewDidLoad method 在viewController.m文件的viewDidLoad方法中尝试一下

for(UIView *view in self.navigationController.navigationBar.subviews)
{
    if([view isKindOfClass:[UIImageView class]])
    {
        [view removeFromSuperview];
    }
}

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navBarBG.png"]];
[self.navigationController.navigationBar addSubview:imageView];
[self.navigationController.navigationBar sendSubviewToBack:imageView];
[imageView release];

[self.navigationController.navigationBar setTintColor:[UIColor clearColor]];

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

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