简体   繁体   中英

iOS 7 UINavigationBar Background image hides Title view

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.

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

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

following code worked for me

In viewDidLoad

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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