iphone - 使图像适合 UINavigationBar 栏

标签 iphone ios objective-c xcode cocoa

我得到了这张图片,我想在我的导航 Controller 中使用它:

enter image description here

我是这样设置的(根据 this 问题的建议):

UINavigationBar *theBar = self.navigationController.navigationBar;
if ( [theBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) {
    UIImage *image = [UIImage imageNamed:@"cabecalho.jpg"];
    [theBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
}

但是当我运行我的应用程序时,我得到了这个:

enter image description here

我该怎么做才能使我的图像适合导航 Controller ?

谢谢。

最佳答案

试试下面的代码

[self.navigationBar setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"myImage.png"]]];

引用How to add background image on iphone Navigation bar?这个问题可能对你有帮助。

关于iphone - 使图像适合 UINavigationBar 栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15778591/

相关文章:

objective-c - 如何使用 ASIHTTPRequest 从 UIWebView 下载文件?

ios - 如何从我的应用程序委托(delegate)启动一个 NSTimer,它调用我在 Viewcontroller.m 中的方法

ios - PUT请求状态码500?

objective-c - 在Objective-C中找到另一个不区分大小写的字符串

iphone - 在单例中设置字典导致 EXC_BAD_ACCESS

iphone - 如何反转音频文件?

iphone - "Our Choice"应用程序如何缩放以查看内容部分?

iphone - 如何检查 UITableViewCells 是否为空白

ios - 将 NSObject 转换为 NSDictionary

ios - iPhone SDK : Not able to access TextField From SearchBar