NavigationBar setShadowImage not always working

别说谁变了你拦得住时间么 提交于 2019-12-03 15:41:47

The Appearance proxy should work.

Just call it somewhere (e.g. in your AppDelegate) upon startup.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{ 
    [self customizeAppearance];
    return YES;
}

- (void) customizeAppearance 
{
    // Set the background image for *all* UINavigationBars
    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navigationbarbackground"] forBarMetrics:UIBarMetricsDefault];

    // Set the shadow image for *all* UINavigationBars
    [[UINavigationBar appearance] setShadowImage:[UIImage imageNamed:@"navigationbarshadow.png"]];  

    //add other appearance stuff here...
}

However if you create a storyboard with multiple UINavigationController's in it and a bunch of segue's pushing navigation controller's you might get a corrupt view controller structure which might be the problem here.

Another possible issue might be the Clip Subviews option of a Navigation Bar somewhere in your nib file or you storyboard. Make sure it is turned off if you want the shadow (image)!

By the way, if you use imageNamed you don't need to include the file extension.

you need to set custom backgroudImage for UINavigationBar, then the shadowImage can work.

Try this !

[[UINavigationBar appearance] setShadowImage:[UIImage imageNamed:@"navbar-iphone.png"]];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!