向 UITabBar 添加颜色 - 非常非常奇怪的错误?
因此,
我对我的 UITabBarController
进行子类化,并将绿色添加到我的 UITabBar
中。
- (void)viewDidLoad {
CGRect frame = CGRectMake(0.0, 0.0, self.view.bounds.size.width, 48);
UIView *v = [[UIView alloc] initWithFrame:frame];
v.backgroundColor = [UIColor greenColor];
[v setAlpha:0.35];
[[self tabBar] insertSubview:v atIndex:0];
[v release];
[super viewDidLoad];
}
这是不行的。
但是如果我尝试 [[self tabBar] insertSubview:v atIndex:1];
它可以工作..并且绿色会添加到整个 TabBar !!
我使用 ios5 SDK 开发 iPhone 模拟器,它工作正常,我能够选择所有选项卡。 但是当我在 ios4.2(真正的 iPhone)上尝试此代码时,第一个选项卡可见..但不响应触摸
原因很明显,因为添加了 SubView
of greenColor
@index ==1;
但是如果我更改为 [[self tabBar] insertSubview:v atIndex:0];
我的第一个选项卡是可选的,但 tabBar
只是不会变成绿色!
敬请指教!!
谢谢。
编辑:
所以问题与iOS5及更早版本有关。 iOS 5 发布后我会编辑答案并放回原来的答案。
现在....前往开发者论坛! :)
So,
I am subclassing my UITabBarController
and I add the color Green to my UITabBar
.
- (void)viewDidLoad {
CGRect frame = CGRectMake(0.0, 0.0, self.view.bounds.size.width, 48);
UIView *v = [[UIView alloc] initWithFrame:frame];
v.backgroundColor = [UIColor greenColor];
[v setAlpha:0.35];
[[self tabBar] insertSubview:v atIndex:0];
[v release];
[super viewDidLoad];
}
This does not work .
But if I try [[self tabBar] insertSubview:v atIndex:1];
it Works .. and a green color is added to the entire TabBar !!
I work on the iPhone Simulator using ios5 SDK
and it works properly and I am able to select all tabs.
But when I try this code on the ios4.2 (real iPhone), the first tab is visible.. but DOES NOT RESPOND TO TOUCH
The reasons is clear, its because of adding a SubView
of greenColor
@ index ==1;
But If I change to [[self tabBar] insertSubview:v atIndex:0];
my firstTab is selectable, but the tabBar
just does not turn Green !!
Kindly Advise !!
Thanks.
Edit:
So the problem is associated with the iOS5 and the earlier versions. I will edit the answer and put back the original answer once iOS 5 is released.
Right now.... Off to the developer forums !!! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想要为此创建一个不子类化 UITabBarController 的自定义控件。根据文档,“您永远不应该直接访问选项卡栏控制器的选项卡栏视图。”
非公共 API 的视图层和层次结构部分可能会因 iOS 版本的不同而发生变化。
You might want to create a custom control for this that does not subclass UITabBarController. From the documentation, "You should never access the tab bar view of a tab bar controller directly."
The view layers and the hierarchy part of the non-public API and subject to change across different version of the iOS.