iPhone:UITabBar自定义图像不起作用 [英] iPhone: UITabBar custom image doesn't work

查看:69
本文介绍了iPhone:UITabBar自定义图像不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下UITTabBar和UINavigationBar内置代码将自己的自定义图像放在Tabbar和导航栏的背景上。它在我的iPhone 3.0应用程序中运行良好。现在,我正在尝试将我的iPhone 3.0应用程序转换为iOS4.0。我现在在Xcode 3.2.3(适用于iOS 4.0)中运行相同的项目,但无法在Tabbar的背景中查看我的自定义Tabbar图像。我试过调试它,但它根本没有调用这个函数UITabbar,但同时它调用UINavigationBar并且工作正常。这个功能(UITabbar)不存在(或)不能在iOS 4.0中使用吗?

I use the following UITTabBar and UINavigationBar built-in code to place my own custom image on the background of Tabbar and Navigation bar. It works great in my iPhone 3.0 application. Now, i am trying to convert my iPhone 3.0 application to iOS4.0. I ran the same project in Xcode 3.2.3(for iOS 4.0) now but unable to view my custom Tabbar image in the background of Tabbar. I tried debugging it, but it is not calling to this function UITabbar at all, but the same time it calls UINavigationBar well and works. Is this function(UITabbar) not there (or) can't use in iOS 4.0?

@implementation UITabBar(CustomImage)

- (void)drawRect:(CGRect)rect {

    UIImage *image = [UIImage imageNamed: @"Tabbar.png"];
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];

}

@end

@implementation UINavigationBar (UINavigationBarCategory)

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

请告知。

谢谢。

推荐答案

我已经通过添加以下代码解决了这个问题:

I have resolved it by adding the code below:

[self.tabBarController.tabBar insertSubview:[ [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Tabbar.png"]] autorelease] atIndex:0];

这篇关于iPhone:UITabBar自定义图像不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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