在iOS中使用导航栏的背景图像时应用程序崩溃
问题描述:
我正在使用导航栏的背景图像。它呈现视图控制器时崩溃了我的应用程序。我也拥有所有视图控制器视图的背景图像。 我使用实施这样在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的(命名AppImagesName.PatternRed)!)崩溃日志。
终止应用程序由于未捕获的异常“NSInternalInconsistencyException”,理由是:“只有RGBA或白色的色彩空间在这种情况下
我用Google搜索这个支持,这一切都是说,除去背景图像或这是iOS的错误。
所以请让我知道可能是什么解决方案。
答
要设置背景图片导航栏,使用下面的代码:
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
公司在哪里德为导航栏设置背景图像? – KSR
@SathiReddy我已经更新了这个问题。请看一看。 –
我正在处理你的问题... – KSR