我想在我的应用中添加设置视图,并且我一直在尝试在设置首选项中更新整个应用的颜色主题。
导航栏和颜色主题似乎没有随用户选择而改变
这是该应用的gif演示: link => demo app settings: theme color not updating
这是我的AppDelegate: 我试图用协议/委托触发更改。没运气 ? 我认为这个问题与代表无关。委托方法正确实现。
问题来自于我相信didFinishLaunching之后需要重新绘制的导航栏。我遇到了这个问题(Changing navigation bar color in Swift),但到目前为止我还没有找到正确的解决方案。这非常具有挑战性
类AppDelegate:UIResponder,UIApplicationDelegate,SettingsDelegate {
var lightColor:UIColor?
var darkColor:UIColor?
var darkColorLighter:UIColor?
var colorThemes:[String : AnyObject] = [String : AnyObject]()
let redColor:UIColor = UIColor(red: 192.0/255.0, green: 57.0/255.0, blue: 43.0/255.0, alpha: 1.0)
var window: UIWindow?
var defaults = UserDefaults.standard
var colorSettingsDefaults = UserDefaults(suiteName: "group.com.Links")
var THEMECOLOR:UIColor?
var TEXTCOLOR:UIColor?
var BORDERADIUS:CGFloat?
var themeSelected:Theme?
let setThemeAppearance:NSNotification.Name = NSNotification.Name("themeAppearance")
func getColorSettingsDefaults(completion:(_ theme:Theme)->()) {
if let _ = colorSettingsDefaults?.value(forKey: "ThemeAppearance") as? String {
//if color settings default avalaible
themeSelected = getTheme()
print("defaults available")
} else {
//if NO color settings default avalaible - default is DARK THEME
themeSelected = .dark
print("dark theme by default")
}
completion(themeSelected!)
}
func getTheme() -> Theme {
return colorSettingsDefaults!.value(forKey: "ThemeAppearance") as! String == "light" ? .light : .dark
}
func applyTheme(themeSelected:Theme) {
if themeSelected == . dark {
THEMECOLOR = darkColor
TEXTCOLOR = lightColor
} else {
THEMECOLOR = lightColor
TEXTCOLOR = darkColor
}
//radius
BORDERADIUS = 5.0
}
func setColorThemes() {
//application theme colors
darkColor = UIColor(red: 52.0/255.0, green: 73.0/255.0, blue: 94.0/255.0, alpha: 1.0)
darkColorLighter = UIColor(red: 52.0/255.0, green: 73.0/255.0, blue: 94.0/255.0, alpha: 0.6)
lightColor = UIColor.white
colorThemes = ["light": lightColor!, "dark": darkColor!]
}
func changeAppearance(apptheme:Theme) {
//change navigation bar title color
UINavigationBar.appearance().barTintColor = THEMECOLOR
UINavigationBar.appearance().tintColor = TEXTCOLOR
window?.rootViewController?.navigationController?.navigationItem.rightBarButtonItem?.tintColor = TEXTCOLOR
if apptheme == .dark {
//change status bar to light for the dark theme
UIApplication.shared.statusBarStyle = .lightContent
} else {
UIApplication.shared.statusBarStyle = .default
}
}
func updateAppearance(appTheme:Theme) {
UINavigationBar.appearance().barTintColor = UIColor.clear
UINavigationBar.appearance().tintColor = UIColor.clear
if appTheme == .dark {
//change status bar to light for the dark theme
UIApplication.shared.statusBarStyle = .lightContent
UINavigationBar.appearance().backgroundColor = darkColor
UINavigationBar.appearance().tintColor = lightColor
window?.rootViewController?.navigationController?.navigationItem.rightBarButtonItem?.tintColor = lightColor
UINavigationBar.appearance().barStyle = .default
} else {
UIApplication.shared.statusBarStyle = .default
UINavigationBar.appearance().backgroundColor = lightColor
UINavigationBar.appearance().tintColor = darkColor
window?.rootViewController?.navigationController?.navigationItem.rightBarButtonItem?.tintColor = darkColor
UINavigationBar.appearance().barStyle = .black
}
}
答案 0 :(得分:1)
Dim iMonth As Long, iYear As Long, sSales As String
With Worksheets("Sheet1")
If .AutoFilterMode Then .AutoFilterMode = False
With Intersect(.Columns("C"), .UsedRange)
For iYear = 2014 To 2020
For iMonth = 1 To 12
sSales = Format(DateSerial(iYear, iMonth, 1), "mmmm \S\a\l\e\s yyyy")
.AutoFilter field:=1, Criteria1:=sSales
With .Resize(.Rows.Count - 1, 1).Offset(1, 0)
If CBool(Application.Subtotal(103, .Cells)) Then
.EntireRow.Delete
End If
End With
Next iMonth
Next iYear
End With
If .AutoFilterMode Then .AutoFilterMode = False
End With