【问题标题】:App crashing when using background image for navigation bar in iOS在 iOS 中使用背景图像作为导航栏时应用程序崩溃
【发布时间】:2017-01-31 19:44:32
【问题描述】:

我正在为导航栏使用背景图片。它在呈现视图控制器时使我的应用程序崩溃。我还拥有所有视图控制器视图的背景图像。 我正在使用这样的实现

func setNavigationAppearance(tintColor : UIColor, barTintColor : UIColor?) {
    let navigationBarAppearace = appDelegateObj.navigationController!.navigationBar

    navigationBarAppearace.tintColor = tintColor
    navigationBarAppearace.barTintColor = barTintColor
    navigationBarAppearace.translucent = false

    //navigationBarAppearace.
    //Settign the Custome Font and TextColor

    if let font = UIFont(name: FontCustom.Regular, size: 17) {
        UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName: font ,NSForegroundColorAttributeName : tintColor]
    }
}

我用这张图片调用这个方法 让 navigationColor : UIColor = UIColor(patternImage: UIImage(named: AppImagesName.PatternRed)!)

我正在获取这些崩溃日志。

由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“在这种情况下仅支持 RGBA 或白色空间

我在谷歌上搜索过,所有人都说删除背景图片或者这是 iOS 错误。

所以请告诉我可能的解决方案。

【问题讨论】:

  • 设置导航栏背景图片的代码在哪里?
  • @SathiReddy 我已经更新了这个问题。请看一看。
  • 我正在处理您的问题...
  • 我添加了代码..请检查..现在我正在将示例项目上传到 GitHub 并提供测试链接..

标签: ios swift uinavigationcontroller uinavigationbar


【解决方案1】:

要将背景图片设置为 NavigationBar,请使用以下代码:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.

        if let myImage = UIImage(named: "navBarImage.jpg"){
            UINavigationBar.appearance().setBackgroundImage(myImage, for: .default)
        }


        return true
    }

示例截图:

要测试示例,请查看我的 GitHub 链接:

https://github.com/k-sathireddy/NavigationBarBackgroundImageSample

【讨论】:

  • 谢谢,我正在测试。
  • 感谢它正在工作。它还没有崩溃。如果它会崩溃,我会告诉你。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-19
  • 1970-01-01
相关资源
最近更新 更多