无法仅在“ios 5.0”中的导航栏上设置图片 [英] Could not set Image on Navigation bar only in "ios 5.0"

查看:121
本文介绍了无法仅在“ios 5.0”中的导航栏上设置图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的通用应用程序中,

In my universal app,

我在导航栏上设置图像...使用**

I am setting an image on navigation bar...using **

objective c category ... on UINavigationBar

**

该代码在iPhone的ios 5.0中正常工作
* 4.3在iPhone / iPad中 *

*But not working in **ios 5.0 iPad***





- (void) drawRect:(CGRect)rect 
    {
    UIImage *image;

   image = [UIImage imageNamed: @"Navigation.png"];

    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];  

      [self setTintColor:[UIColor clearColor]];

      NSLog(@"Draw Rect");

    }


推荐答案

iOS 5中导航栏的BG图像,您可以使用以下代码

To set a BG image for navigation bar in iOS 5 you can use the below code

if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"Navigation.png"] forBarMetrics:UIBarMetricsDefault];
}

但请记住,这不会在iOS 4中工作。工作在两个你还需要添加一个类别到UINavigationBar

But please keep in mind that this wont work in iOS 4. To make it work in both you also need to add a category to UINavigationBar

@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
UIImage *img = [UIImage imageNamed:@"Navigation.png"];
[img drawInRect:rect];
}

这篇关于无法仅在“ios 5.0”中的导航栏上设置图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆