iOS 7 UINavigationBar Background image hides Title view

别来无恙 提交于 2019-12-12 09:53:09

问题


I made iOS app, in which i want my app to compatible with 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

:
-(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

When i run my apps prior to iOS 7 it works properly.

Please help. Thanks in advance.


回答1:


Behavior of tintColor for bars has changed on iOS 7.0, please check the image below:

You can see that

tintColor: is the color for the interactive elements within a navigation bar including button images and titles.

barTintColor is the background color of the UINavigationBar.

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];



回答2:


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]];



回答3:


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




回答4:


following code worked for me

In viewDidLoad

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


来源:https://stackoverflow.com/questions/18821622/ios-7-uinavigationbar-background-image-hides-title-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!