gpt4 book ai didi

ios - 在 swift 5 中使用 UITabBar.appearance().bar 样式崩溃

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:58:07 25 4
gpt4 key购买 nike

我实现了“深色模式”,我需要将 TabBar 样式从默认更改为深色,或者相反。

我的应用崩溃了!

我该怎么办?

2019-08-28 21:42:57.276131+0200 Score[1817:344811] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Bar style not supported by UITabBar. Supported bar styles are UIBarStyleDefault and UIBarStyleBlack' * First throw call stack: (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: terminating with uncaught exception of type 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

//...

}
}

最佳答案

异常的终止原因说明:

Supported bar styles are UIBarStyleDefault and UIBarStyleBlack

看来我们所要做的就是将 barStyle 修改为:

var barStyle: UIBarStyle {
switch self {
case .Light:
return .default
case .Dark:
return .black
}
}

关于ios - 在 swift 5 中使用 UITabBar.appearance().bar 样式崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57700148/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com