简体   繁体   English

iOS 7 UINavigationBar背景图像隐藏标题视图

[英]iOS 7 UINavigationBar Background image hides Title view

I made iOS app, in which i want my app to compatible with iOS 7 我制作了iOS应用,希望其中的应用与iOS 7兼容

Problem which i am facing is, when i run my app on iOS 7, Background image of my UINavigationBar hides my titleview and back button 我面临的问题是,当我在iOS 7上运行我的应用程序时, UINavigationBar背景图像隐藏了我的titleviewback button

屏幕截图在这里 :

-(void)viewDidLoad
{
    [super viewDidLoad];

    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"top.png"] forBarMetrics:UIBarMetricsDefault];

    self.title=@"Artist";
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];


}

also when, i set Background image of UINavigationBar to nil it shows titleview and back button 同样,当我将UINavigationBar背景图像设置为nil时,它显示titleviewback button

When i run my apps prior to iOS 7 it works properly. 当我在iOS 7之前运行我的应用程序时,它可以正常运行。

Please help. 请帮忙。 Thanks in advance. 提前致谢。

Behavior of tintColor for bars has changed on iOS 7.0, please check the image below: 在iOS 7.0上,酒吧的tintColor行为已更改,请检查下图:

在此处输入图片说明

You can see that 你可以看到

tintColor : is the color for the interactive elements within a navigation bar including button images and titles. tintColor :是导航栏中的交互式元素的颜色,包括按钮图像和标题。

barTintColor is the background color of the UINavigationBar . barTintColorUINavigationBar的背景色。

For your issue: you can do the below: 针对您的问题:您可以执行以下操作:

navigationBar.tintColor = [UIColor whiteColor];
navigationBar.barTintColor = [UIColor colorWithRed:6.0/255.0 green:12.0/255.0 blue:19.0/255.0 alpha:1.0];

The default font color is black so you are probably drawing a black font on a black background. 默认字体颜色是黑色,因此您可能正在黑色背景上绘制黑色字体。 Try the following: 请尝试以下操作:

[[UINavigationBar appearance] setTitleTextAttributes:
                              [NSDictionary dictionaryWithObjectsAndKeys:
                              [UIColor whiteColor], NSForegroundColorAttributeName,nil]];

check the property extend edges on the property inspector of your view this will extend the edges from the bottom of your navigation bar to the top of your screen so your background image will be at the right place 检查属性在视图的属性检查器上的延伸边缘,这会将边缘从导航栏的底部延伸到屏幕的顶部,以便背景图像位于正确的位置

在此处输入图片说明

check the transition guide for ios7 if you want more info about new things in ios7 https://developer.apple.com/library/prerelease/ios/documentation/UserExperience/Conceptual/TransitionGuide/index.html 如果您想了解有关ios7中新事物的更多信息,请查看ios7的过渡指南https://developer.apple.com/library/prerelease/ios/documentation/UserExperience/Conceptual/TransitionGuide/index.html

following code worked for me 以下代码为我工作

In viewDidLoad 在viewDidLoad中

    self.navigationController.navigationBar.tintColor=[UIColor whiteColor];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM