gpt4 book ai didi

iphone - 选择时如何更改 UITabBarItem 标题的颜色

转载 作者:行者123 更新时间:2023-11-28 22:47:44 25 4
gpt4 key购买 nike

我的环境,

iOS6
Xcode 4.5.1

我想在选中时更改 UITabBarItem 标题的颜色。

我将 CustomUITabBarItem 用于 UITabBarItem。- customUITabBarItem.m

@implementation customUITabBarItem

@synthesize customHighlightedImage;

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

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

@end

ViewController.m

#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;
}

如何改变颜色?

最佳答案

 [self.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"AmericanTypewriter" size:20.0f], UITextAttributeFont,
[UIColor blackColor], UITextAttributeTextColor,
[UIColor grayColor],
nil]];

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

关于iphone - 选择时如何更改 UITabBarItem 标题的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12778231/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com