tabbar item image and selectedImage

前端 未结 2 1940
误落风尘
误落风尘 2020-12-06 04:10

I have a tab bar controller (its a tab bar based application, so tab bar is on MainWindow.xib). In this xib, I have added 4 tab bar items and I have set the image of all tab

2条回答
  •  执笔经年
    2020-12-06 04:28

    Based on http://blog.theanalogguy.be/ works for me. Add the category UItabBarItem (CustomUnselectedImage) - haven't effect =(

    the *.h

    @interface CustomTabBarItem : UITabBarItem {  
        UIImage *customHighlightedImage;  
        UIImage *customNormalImage;  
    }  
    
    @property (nonatomic, retain) UIImage *customHighlightedImage;  
    @property (nonatomic, retain) UIImage *customNormalImage;  
    
    - (id)initWithTitle:(NSString *)title 
            normalImage:(UIImage *)normalImage 
        highlightedImage:(UIImage *)highlightedImage 
                    tag:(NSInteger)tag;
    @end
    

    and *.m

    #import "CustomTabBarItem.h"
    
    @implementation CustomTabBarItem  
    
    @synthesize customHighlightedImage;  
    @synthesize customNormalImage;  
    
    - (id)initWithTitle:(NSString *)title 
            normalImage:(UIImage *)normalImage 
        highlightedImage:(UIImage *)highlightedImage 
                    tag:(NSInteger)tag{
    
        [self initWithTitle:title
                        image:nil
                        tag:tag];
        [self setCustomNormalImage:normalImage];
        [self setCustomHighlightedImage:highlightedImage];
        return self;
    }
    
    - (void) dealloc  
    {  
        [customHighlightedImage release];
        customHighlightedImage=nil;  
        [customNormalImage release]; 
        customNormalImage=nil;  
        [super dealloc];  
    }  
    
    -(UIImage *) selectedImage  
    {  
        return self.customHighlightedImage;  
    }  
    
    -(UIImage *) unselectedImage  
    {  
        return self.customNormalImage;  
    }  
    
    @end  
    

    happy coding =]-

提交回复
热议问题