Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone Xcode 4.3.2 UINavigationBar图像背景_Iphone_Uinavigationcontroller_Uinavigationbar_Xcode4.3 - Fatal编程技术网

Iphone Xcode 4.3.2 UINavigationBar图像背景

Iphone Xcode 4.3.2 UINavigationBar图像背景,iphone,uinavigationcontroller,uinavigationbar,xcode4.3,Iphone,Uinavigationcontroller,Uinavigationbar,Xcode4.3,我正在使用UINavigation controller在xCode 4.3.2中创建一个tabBar应用程序。我在AppDelegate中使用以下代码 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen m

我正在使用UINavigation controller在xCode 4.3.2中创建一个tabBar应用程序。我在AppDelegate中使用以下代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
   // Override point for customization after application launch.
   UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease];
   UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease];
   self.tabBarController = [[[UITabBarController alloc] init] autorelease];
   self.tabBarController.viewControllers = [NSArray arrayWithObjects:
                                         [[[UINavigationController alloc] initWithRootViewController:viewController1] autorelease], viewController2, nil];
   self.window.rootViewController = self.tabBarController;
   [self.window makeKeyAndVisible];
   return YES;
}
现在的问题是,我想在导航栏自定义背景图像。我找到的解决方案是编写UINavigationBar的子类,并在interface builder中设置新的子类。但在我的例子中,我以编程方式设置导航控制器,那么如何实现这一点呢? 我也尝试过创建类别作为

@implementation UINavigationBar (CustomImage)
- (void)drawRect:(CGRect)rect {
    UIImage *image = [UIImage imageNamed:@"NavigationBar.png"];
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
@end  

但它根本不起作用。

对于导航栏,请使用以下命令:

UIImage *image = [UIImage imageNamed: @"NavBarImage.png"];
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];`

and for Tabbar:

    // not supported on iOS4    
    UITabBar *tabBar = [tabController tabBar];
    if ([tabBar respondsToSelector:@selector(setBackgroundImage:)])
    {
        // set it just for this instance
        [tabBar setBackgroundImage:[UIImage imageNamed:@"tabbar_brn.jpg"]];

        // set for all
        // [[UITabBar appearance] setBackgroundImage: ...
    }
    else
    {
        // ios 4 code here
    }

感谢浏览栏使用以下内容:

UIImage *image = [UIImage imageNamed: @"NavBarImage.png"];
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];`

and for Tabbar:

    // not supported on iOS4    
    UITabBar *tabBar = [tabController tabBar];
    if ([tabBar respondsToSelector:@selector(setBackgroundImage:)])
    {
        // set it just for this instance
        [tabBar setBackgroundImage:[UIImage imageNamed:@"tabbar_brn.jpg"]];

        // set for all
        // [[UITabBar appearance] setBackgroundImage: ...
    }
    else
    {
        // ios 4 code here
    }

谢谢

您想设置选项卡栏或导航栏的背景图像。您的问题标题已发布到导航栏,您发布了tabbar的代码???Mitesh Khatri,我想设置导航栏的背景图像,我发布了代码以显示如何添加导航控制器。我试图将navigationBar子类化,但我不知道如何将navigationBar类设置为我的新子类,因为我正在以编程方式进行所有操作。Thanx正在等待您的回复您可以在您想要设置Tabbar或导航栏背景图像的位置查看我的帖子。您的问题标题已发布到导航栏,您发布了tabbar的代码???Mitesh Khatri,我想设置导航栏的背景图像,我发布了代码以显示如何添加导航控制器。我试图将navigationBar子类化,但我不知道如何将navigationBar类设置为我的新子类,因为我正在以编程方式进行所有操作。Thanx正在等待您的回复您可以在Thanx Mitesh Khatri上看到我的帖子,但我正在寻找backword兼容的解决方案,至少适用于iOS 4。Thanx Mitesh Khatri,但我正在寻找backword兼容的解决方案,至少适用于iOS 4。