【发布时间】:2020-01-02 03:19:23
【问题描述】:
我实现了“深色模式”,我需要将 TabBar 样式从默认更改为深色,反之亦然。
我的应用崩溃了!
我该怎么办?
2019-08-28 21:42:57.276131+0200 分数[1817:344811] * 终止应用 由于未捕获的异常'NSInvalidArgumentException',原因:'Bar UITabBar 不支持的样式。支持的栏样式是 UIBarStyleDefault 和 UIBarStyleBlack' * 首先抛出调用栈: (0x19ef4aab8 0x19e14fd00 0x19ee502f4 0x1cbbd5f08 0x19ef52414 0x19ee4d0bc 0x1cbfb610c 0x1cc7f9e44 0x1cbfb6098 0x1cbfb03b8 0x1cbfaf7d8 0x1cc822ee4 0x1cc822e54 0x1cbbd8790 0x1cc822d58 0x1cc822174 0x1cbbda498 0x1cc821edc 0x1cc8152ac 0x1cc815170 0x1cc824d20 0x1cc3ac68c 0x1cc3acab0 0x1cc3bd80c 0x1cc36e090 0x1cc3739fc 0x1cbc05e04 0x1cbc0e7e0 0x1cbc05a6c 0x1cbc06388 0x1cbc045d0 0x1cbc0428c 0x1cbc08fbc 0x1cbc09e14 0x1cbc08e70 0x1cbc0de60 0x1cc371f38 0x1cbf54650 0x1a190dfd0 0x1a191831c 0x1a1917a6c 0x1004f477c 0x1004f833c 0x1a194b18c 0x1a194ae08 0x1a194b404 0x19eedab54 0x19eedaad0 0x19eeda38c 0x19eed5060 0x19eed4964 0x1a1115d8c 0x1cc375758 0x1000a96ec 0x19e990fd8) libc++abi.dylib:以 NSException 类型的未捕获异常终止
enum Theme: Int {
case Light, Dark
var barStyle: UIBarStyle {
switch self {
case .Light:
return .default
case .Dark:
return .blackTranslucent
}
}
//...
}
class ThemeManager {
static func applyTheme(theme: Theme) {
if(theme == .Dark){
UserDefaults.standard.set(true, forKey: "darkMode")
} else {
UserDefaults.standard.set(false, forKey: "darkMode")
}
UserDefaults.standard.synchronize()
let sharedApplication = UIApplication.shared
sharedApplication.delegate?.window??.tintColor = theme.buttonColor
UINavigationBar.appearance().barStyle = theme.barStyle
UITabBar.appearance().barStyle = theme.barStyle
UITabBar.appearance().barTintColor = theme.labelColor
UINavigationBar.appearance().tintColor = theme.labelColor
//...
}
}
【问题讨论】:
-
您在哪个 iOS 版本上运行您的应用程序?
-
我运行的是最新版本的 iOS 12.4.1
标签: ios swift background-color uitabbar