iOS 中的导航栏使用背景图片时应用程序崩溃
App crashing when using background image for navigation bar in iOS
我正在为导航栏使用背景图片。它在呈现视图控制器时使我的应用程序崩溃。我还有所有视图控制器视图的背景图像。
我正在使用这样的实现
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)!)
我收到了这些崩溃日志。
terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only RGBA or White color spaces are supported in this situation
我用谷歌搜索了一下,所有人都说删除背景图片或者这是 iOS 错误。
所以请告诉我可能的解决方案。
要为 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 link:
https://github.com/k-sathireddy/NavigationBarBackgroundImageSample
我正在为导航栏使用背景图片。它在呈现视图控制器时使我的应用程序崩溃。我还有所有视图控制器视图的背景图像。 我正在使用这样的实现
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)!)
我收到了这些崩溃日志。
terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only RGBA or White color spaces are supported in this situation
我用谷歌搜索了一下,所有人都说删除背景图片或者这是 iOS 错误。
所以请告诉我可能的解决方案。
要为 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 link:
https://github.com/k-sathireddy/NavigationBarBackgroundImageSample