Objective-C:导航栏中的背景图像和标题
我的导航栏中需要背景图像和标题。对于图像,我编写了一个类别:
@implementation UINavigationBar(MyNavigationBar)
- (void)setBackgroundImage {
UIImageView *aTabBarBackground = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"navBarBackgrd.png"]];
[self addSubview: aTabBarBackground];
[self sendSubviewToBack: aTabBarBackground];
[aTabBarBackground release];
}
@end
我在 AppDelegate 中调用这个类别,并且在整个应用程序中都有背景图像:
[navigationController.navigationBar setBackgroundImage];
每个 ViewController 都有一个标题:
[self setTitle:@"MyTitle"];
但是设置背景图像后,我的标题出现了问题。
在每件作品的第一个视图中,我都会看到背景图片和标题:-) 但在下一个视图中,标题消失了。仅背景图像可见。也许标题在图片下面?
从技术上讲,两者都可以显示。通过这个技巧,它可以工作:
在打开下一个 ViewController 之前隐藏导航栏:
[self.navigationController setNavigationBarHidden:YES];
在下一个 ViewController 中显示导航栏:
[self.navigationController setNavigationBarHidden:NO];
现在,图像和标题可见,但这个解决方案不是最好的;-)
In need a background image AND a title in my Navigation Bar. For the image I write a category:
@implementation UINavigationBar(MyNavigationBar)
- (void)setBackgroundImage {
UIImageView *aTabBarBackground = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"navBarBackgrd.png"]];
[self addSubview: aTabBarBackground];
[self sendSubviewToBack: aTabBarBackground];
[aTabBarBackground release];
}
@end
I call this category in my AppDelegate and have background images in the whole application:
[navigationController.navigationBar setBackgroundImage];
Every ViewController has a title:
[self setTitle:@"MyTitle"];
But after setting the background image, I have a problem with the title.
In the first view every works, I see the background image and the title :-)
But in the next view, the title disappears. Only the background image is visible. Maybe the title is under the image?
Technically it's possible to show both. With this trick it works:
Hide Navigation Bar BEFORE opening the next ViewController:
[self.navigationController setNavigationBarHidden:YES];
Show the Navigation Bar in the next ViewController:
[self.navigationController setNavigationBarHidden:NO];
Now, image AND title are visible, but this solution isn't the best ;-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我得到了它!
请参阅导航视图的背景图片
I got it!
See Background image for navigation view
在IOS5之后你应该这样做,例如在AppDelegate中
After IOS5 You should do this, for example in AppDelegate