forked from zelo72/mastodon-ios
fix: setting switch use wrong tint color issue
This commit is contained in:
parent
74334126f0
commit
7f597c2082
|
@ -20,7 +20,6 @@ class SettingsToggleTableViewCell: UITableViewCell {
|
||||||
|
|
||||||
private(set) lazy var switchButton: UISwitch = {
|
private(set) lazy var switchButton: UISwitch = {
|
||||||
let view = UISwitch(frame:.zero)
|
let view = UISwitch(frame:.zero)
|
||||||
view.onTintColor = contentView.window?.tintColor ?? .label
|
|
||||||
return view
|
return view
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -49,8 +48,15 @@ class SettingsToggleTableViewCell: UITableViewCell {
|
||||||
accessoryView = switchButton
|
accessoryView = switchButton
|
||||||
textLabel?.numberOfLines = 0
|
textLabel?.numberOfLines = 0
|
||||||
|
|
||||||
|
updateAppearance()
|
||||||
switchButton.addTarget(self, action: #selector(switchValueDidChange(sender:)), for: .valueChanged)
|
switchButton.addTarget(self, action: #selector(switchValueDidChange(sender:)), for: .valueChanged)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
|
||||||
|
super.traitCollectionDidChange(previousTraitCollection)
|
||||||
|
|
||||||
|
updateAppearance()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,4 +78,16 @@ extension SettingsToggleTableViewCell {
|
||||||
switchButton.isOn = enabled ?? false
|
switchButton.isOn = enabled ?? false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func updateAppearance() {
|
||||||
|
switchButton.onTintColor = {
|
||||||
|
switch traitCollection.userInterfaceStyle {
|
||||||
|
case .dark:
|
||||||
|
// set default green for Dark Mode
|
||||||
|
return nil
|
||||||
|
default:
|
||||||
|
// set tint black for Light Mode
|
||||||
|
return self.contentView.window?.tintColor ?? nil
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue