开发者

Adding Color to UITabBar - Very very Weird Bug?

开发者 https://www.devze.com 2023-03-29 16:34 出处:网络
So, I am subclassing my UITabBarController and I add the color Green to my UITabBar. - (void)viewDidLoad {

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];
    开发者_如何学C[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 !!! :)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号