如何去除 ios 14 的导航栏图像阴影?

How to remove navigationbar image shadow for ios 14?

enter image description here
我在 objective c 中面临 ios 版本 问题。 导航栏图像阴影ios 14 版本 中不起作用。 ios < 14 工作正常。我上传图片 所以这是我的代码


if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 14.0)
{
    [[UINavigationBar appearance] setBackgroundImage: [UIImage new]
                                       forBarMetrics: UIBarMetricsDefault];
    [UINavigationBar appearance].shadowImage = [UIImage new];

    //[[UINavigationBar appearance] setBackgroundImage:blank forBarMetrics:UIBarMetricsDefault];

}
else
{
    // Load resources for iOS 11 or earlier
    self.navigationController.navigationBar.shadowImage = [UIImage alloc];

}

我解决了以下问题是我的代码:

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 14.0)
{
    [[UINavigationBar appearance] setBackgroundImage: [UIImage new]
                                       forBarMetrics: UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [UIImage new];
    [UINavigationBar appearance].tintColor = UIColor.clearColor;
    self.navigationController.navigationBar.translucent = YES;

}
else
{
    // Load resources for iOS 11 or earlier
    self.navigationController.navigationBar.shadowImage = [UIImage alloc];

}

在objective-c

[[UINavigationBar appearance] setBackgroundImage: [UIImage new]
                                   forBarMetrics: UIBarMetricsDefault];
self.navigationController.navigationBar.translucent = YES;
self.navigationController.navigationBar.shadowImage = [UIImage new];
[UINavigationBar appearance].tintColor = UIColor.clearColor;

在Swift5

UINavigationBar.appearance().setBackgroundImage(UIImage(), forBarPosition: UIBarPosition.Any, barMetrics: UIBarMetrics.Default)
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().tintColor = UIColor.whiteColor()
UINavigationBar.appearance().translucent = false
UINavigationBar.appearance().clipsToBounds = false