iPhone SDK - UITabBarConroller 和定制设计
我的屏幕底部的标签栏出现问题。设计师决定,当不活动时它应该是一种颜色(不是黑色),而当活动时它应该是另一种颜色。我已经弄清楚如何通过子类化 UITabBarController 并执行以下操作来替换选项卡栏的主颜色:-
- (void)viewDidLoad {
[super viewDidLoad];
CGRect frame = CGRectMake(0.0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
UIView *v = [[UIView alloc] initWithFrame:frame];
//get percentage values from digitalcolour meter and enter as decimals
v.backgroundColor = [UIColor colorWithRed:.0 green:.706 blue:.863 alpha:1];
[tabBar1 insertSubview:v atIndex:0];
[v release];
}
我只是看不到如何使活动选项卡栏在选择时成为单独的颜色。我尝试过对 UITabBarItem 进行子类化,但似乎没有任何属性可供我设置来更改选项卡的背景颜色。
他们还希望标签栏上的图标不是蓝色和灰色的,我不知道该怎么做。在一个选项卡栏项目的 ViewController 中,我已将其放入 viewdidload:-
myTabBarItem *tabItem = [[myTabBarItem alloc] initWithTitle:@"listOOO" image:[UIImage imageNamed:@"starcopy.png"] tag:1];
tabItem.customHighlightedImage=[UIImage imageNamed:@"starcopy.png"];
self.tabBarItem=tabItem;
[tabItem release];
tabItem=nil;
在 UITabBarItem 的子类中,我已将其放入:-
-(UIImage *) selectedImage{
return self.customHighlightedImage;
}
只是我根本看不到该图标。
如果我将其放入 UITabBarController 子类的 viewDidLoad 中:-
for (UITabBarItem *item in tabBar1.items){
item.image = [UIImage imageNamed:@"starcopy.png"];
}
那么我所有的选项卡栏都有图标,但它们是蓝色的(不活动时是灰色的)我怎样才能让它们不变成蓝色但保持原来的颜色?
如果您对这个问题有任何了解,请帮忙,因为我已经把头靠在墙上两天了,这让我很沮丧。 提前致谢 谢丽尔
I am having a problem with my tab bars at the bottom of the screen. The designer has decided it should be one colour (not black) when inactive and another colour when active. I have worked out how to replace the main colour of the tabbar by subclassing UITabBarController and doing this:-
- (void)viewDidLoad {
[super viewDidLoad];
CGRect frame = CGRectMake(0.0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
UIView *v = [[UIView alloc] initWithFrame:frame];
//get percentage values from digitalcolour meter and enter as decimals
v.backgroundColor = [UIColor colorWithRed:.0 green:.706 blue:.863 alpha:1];
[tabBar1 insertSubview:v atIndex:0];
[v release];
}
I just can't see how to make the active tabbar be a separate colour when it is selected. I have tried subclassing UITabBarItem but there doesn't seem to be any property for me to set to change the background colour of the tab.
They also want to have the icons on the tab bar not be blue and grey and I can't figure out how to do that. In the ViewController for one tab bar item I have put this into viewdidload:-
myTabBarItem *tabItem = [[myTabBarItem alloc] initWithTitle:@"listOOO" image:[UIImage imageNamed:@"starcopy.png"] tag:1];
tabItem.customHighlightedImage=[UIImage imageNamed:@"starcopy.png"];
self.tabBarItem=tabItem;
[tabItem release];
tabItem=nil;
and in my subclass of UITabBarItem I have put this:-
-(UIImage *) selectedImage{
return self.customHighlightedImage;
}
Only I don't see the icon at all.
If I put this into the viewDidLoad of my subclass of UITabBarController:-
for (UITabBarItem *item in tabBar1.items){
item.image = [UIImage imageNamed:@"starcopy.png"];
}
Then all my tab bars have the icon but they are blue (and grey when inactive) how would I get them not to become blue but stay their original colour?
If you have any light on this problem please help as I have been banking my head on the wall for 2 days now and it's getting me down.
Thanks in advance
Cheryl
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果不使用私有 API 调用,这似乎是不可能完成的。我现在能看到的唯一解决方案是创建一个完整的自定义 TabBar。然而,仅仅为了以不同的颜色呈现图标就需要大量工作。
It seems to be impossible to be done without using private API calls. The only solution I can see right now is to create a complete custom TabBar. That however is a lot of work just to get an icon presented in a different color.