简体   繁体   中英

iPhone: UITabBar custom image doesn't work

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

Please advise.

Thank you.

我通过添加以下代码解决了它:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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