0

我以前用过这段代码,现在不行了。我正在使用渐变图像添加导航栏背景。这在 xcode 11.4 更新之前有效,但更新后它停止工作。此外,标题也以黑色显示。我尝试改变颜色它没有工作。

var img = UIImage.FromBundle("navbar_image").CreateResizableImage(UIEdgeInsets.Zero, UIImageResizingMode.Stretch);
NavigationController.NavigationBar.SetBackgroundImage(img, UIBarMetrics.Default);

这是在imgae之前这是在imgae之前

现在它显示为这样,标题为黑色现在它显示为这样,标题为黑色

4

1 回答 1

0

这段代码对我有用。

if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
        {
            UINavigationBarAppearance appearance = new UINavigationBarAppearance();
            var img = UIImage.FromBundle("navbar_image").CreateResizableImage(UIEdgeInsets.Zero, UIImageResizingMode.Stretch);
            appearance.BackgroundImage = img;
            appearance.TitleTextAttributes = new UIStringAttributes { ForegroundColor = UIColor.White };
            appearance.BackgroundColor = UIColor.Blue;
            NavigationController.NavigationBar.CompactAppearance = appearance;
            NavigationController.NavigationBar.StandardAppearance = appearance;
            NavigationController.NavigationBar.ScrollEdgeAppearance = appearance;

        }
        else
        {
            var img = UIImage.FromBundle("navbar_image").CreateResizableImage(UIEdgeInsets.Zero, UIImageResizingMode.Stretch);
            NavigationController.NavigationBar.SetBackgroundImage(img, UIBarMetrics.Default);
            this.NavigationController.NavigationBar.Translucent = false;
        }
于 2020-04-03T10:23:42.553 回答