Commit fc449841 by Demid Merzlyakov

Settings / Theme Selection: images are tappable. An ability to disable automatic.

parent 339c720e
...@@ -68,16 +68,26 @@ class SettingsThemeCell: UITableViewCell { ...@@ -68,16 +68,26 @@ class SettingsThemeCell: UITableViewCell {
@objc private func handleThemeButton(button: UIButton) { @objc private func handleThemeButton(button: UIButton) {
switch button { switch button {
case lightThemeButton: case lightThemeButton:
Settings.shared.appTheme = .light selectLightTheme()
case darkThemeButton: case darkThemeButton:
Settings.shared.appTheme = .dark selectDarkTheme()
default: default:
break break
} }
} }
@objc private func handleAutomaticSwith() { @objc private func handleAutomaticSwith() {
Settings.shared.appTheme = .system if automaticSwitchButton.isOn {
Settings.shared.appTheme = .system
}
else {
switch interfaceStyle {
case .light:
Settings.shared.appTheme = .light
case .dark:
Settings.shared.appTheme = .dark
}
}
} }
//Public //Public
...@@ -104,13 +114,27 @@ private extension SettingsThemeCell { ...@@ -104,13 +114,27 @@ private extension SettingsThemeCell {
} }
} }
@objc
private func selectLightTheme() {
Settings.shared.appTheme = .light
}
@objc
private func selectDarkTheme() {
Settings.shared.appTheme = .dark
}
func prepareLightTheme() { func prepareLightTheme() {
lightThemeImageView.clipsToBounds = true lightThemeImageView.clipsToBounds = true
lightThemeImageView.layer.cornerRadius = 10 lightThemeImageView.layer.cornerRadius = 10
lightThemeImageView.contentMode = .scaleAspectFill lightThemeImageView.contentMode = .scaleAspectFill
lightThemeImageView.image = UIImage(named: "theme_sample_light") lightThemeImageView.image = UIImage(named: "theme_sample_light")
lightThemeImageView.isUserInteractionEnabled = true
container.addSubview(lightThemeImageView) container.addSubview(lightThemeImageView)
let gesture = UITapGestureRecognizer(target: self, action: #selector(selectLightTheme))
lightThemeImageView.addGestureRecognizer(gesture)
lightThemeLabel.textAlignment = .center lightThemeLabel.textAlignment = .center
lightThemeLabel.setContentHuggingPriority(.fittingSizeLevel, for: .vertical) lightThemeLabel.setContentHuggingPriority(.fittingSizeLevel, for: .vertical)
lightThemeLabel.font = AppFont.SFPro.regular(size: 16) lightThemeLabel.font = AppFont.SFPro.regular(size: 16)
...@@ -145,8 +169,12 @@ private extension SettingsThemeCell { ...@@ -145,8 +169,12 @@ private extension SettingsThemeCell {
darkThemeImageView.clipsToBounds = true darkThemeImageView.clipsToBounds = true
darkThemeImageView.contentMode = .scaleAspectFill darkThemeImageView.contentMode = .scaleAspectFill
darkThemeImageView.image = UIImage(named: "theme_sample_dark") darkThemeImageView.image = UIImage(named: "theme_sample_dark")
darkThemeImageView.isUserInteractionEnabled = true
container.addSubview(darkThemeImageView) container.addSubview(darkThemeImageView)
let gesture = UITapGestureRecognizer(target: self, action: #selector(selectDarkTheme))
darkThemeImageView.addGestureRecognizer(gesture)
darkThemeLabel.textAlignment = .center darkThemeLabel.textAlignment = .center
darkThemeLabel.font = AppFont.SFPro.regular(size: 16) darkThemeLabel.font = AppFont.SFPro.regular(size: 16)
darkThemeLabel.text = "settings.theme.dark".localized() darkThemeLabel.text = "settings.theme.dark".localized()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment