Iphone 如何更改uitabaritem';当它';s selecetd

Iphone 如何更改uitabaritem';当它';s selecetd,iphone,ios,xcode4,Iphone,Ios,Xcode4,我的环境 我想在选定Uitabritem标题时更改其颜色 我使用customuitabaritem作为uitabaritem。 -customuitabaritem.m iOS6 Xcode 4.5.1 ViewController.m @implementation customUITabBarItem @synthesize customHighlightedImage; -(UIImage *) selectedImage { return self.customHighli

我的环境

我想在选定Uitabritem标题时更改其颜色

我使用customuitabaritem作为uitabaritem。 -customuitabaritem.m

iOS6
Xcode 4.5.1
ViewController.m

@implementation customUITabBarItem

@synthesize customHighlightedImage;

-(UIImage *) selectedImage
{
    return self.customHighlightedImage;
}

- (void) dealloc
{
    [customHighlightedImage release];
    customHighlightedImage=nil;
    [super dealloc];
}

@end
我怎样才能改变颜色

#import "FirstViewController.h"
#import "customUITabBarItem.h"


@interface FirstViewController ()

@end

@implementation FirstViewController

- (void)viewDidLoad
{   
    [super viewDidLoad];
    CustomUITabBarItem *tabItem = [[customUITabBarItem alloc] initWithTitle:@"first" image:[UIImage imageNamed:@"first.png"] tag:0]; 
    tabItem.customHighlightedImage = [UIImage imageNamed:@"first_selected.png"];
    self.tabBarItem = tabItem;
    [tabItem release];
    tabItem = nil;
}   

请确保这只适用于iOS 5.0或更高版本。

您可以看到此链接您可以看到此链接很多!但是,我需要在最后添加“forState:UIControlStateSelected”。无论如何,我可以做得很好。谢谢你的评论,但是有一个警告,“UITabView可能不会响应setBackgroundColor”,并且命令不能很好地工作。
 [self.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                            [UIFont fontWithName:@"AmericanTypewriter" size:20.0f], UITextAttributeFont,
                                            [UIColor blackColor], UITextAttributeTextColor,
                                            [UIColor grayColor],        
                                            nil]];
//it easy to change color
-(void)your_method
{
// your actions
[tabItem setBackgroundColor:[UIColor redColor]];
}
#define SYSTEM_OS [[[UIDevice currentDevice] systemVersion] intValue]
- (void) setTabBarColors {

    if (SYSTEM_OS >= 5) {

        self.tabBarController.tabBar.tintColor = [UIColor blueColor];
        self.tabBarController.tabBar.selectedImageTintColor = [UIColor magentaColor];

        __block NSDictionary *dict1 = [NSDictionary dictionaryWithObjectsAndKeys:
                                       [UIFont fontWithName:@"ArialMT" size:12.0f], UITextAttributeFont,
                                       [UIColor lightGrayColor], UITextAttributeTextColor,
                                       nil];



        __block NSDictionary *dict2 = [NSDictionary dictionaryWithObjectsAndKeys:
                                       [UIFont fontWithName:@"ArialMT" size:12.0f], UITextAttributeFont,
                                       [UIColor whiteColor], UITextAttributeTextColor,
                                       nil];

        [self.tabBarController.viewControllers enumerateObjectsUsingBlock:^(UIViewController * obj, NSUInteger idx, BOOL *stop) {

            [obj.tabBarItem setTitleTextAttributes:dict1 forState:UIControlStateNormal];
            [obj.tabBarItem setTitleTextAttributes:dict2 forState:UIControlStateSelected];

        }];

    }

}