开发者

UINavigationBar custom title being hidden by background

开发者 https://www.devze.com 2023-04-03 22:03 出处:网络
I am adding a custom UIImageView to my UINavigationBar using this code: UIImageView *background = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)] autorelease];

I am adding a custom UIImageView to my UINavigationBar using this code:

UIImageView *background = [[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)] autorelease];
[background setImage:[UIImage imageNamed:@"nav_background.png"]];
[background setTag:kTagForReference];
[self.navigationController.navigationBar insertSubview:background atIndex:0];

I then add a custom title using this code:

UILa开发者_如何转开发bel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 400, 44)];
... 
[self.navigationItem setTitleView:label];
[label release];

But on some of my pushed views the title is being hidden (or isn't visible). I can't seem to push more than two views onto the stack without the title disappearing.

I've tried to force my UIImageView background to the back of the bar but that still doesn't help. I've printed the subviews of the UINavigationBar and I can see that the UILabel is there, I just can't see it!

Any help would be greatly appreciated.


If you can run the dumpWindows() function, the output would show the view hierarchy so you can see what view is covering it up.


You most likely want to use a UIToolBar instead of a NavigationBar. Then you can add the subviews to the UIToolbar.

Bring the UILabel to the front most view.

[self.view bringSubviewToFront: label];
0

精彩评论

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