diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2021-10-08 14:37:31 +0200 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2021-11-03 13:30:51 +0100 |
| commit | 7048540407083c7e557bac2419fbbb6d3433f868 (patch) | |
| tree | 43958994afdad1ae02005a2f98ed90aa521c1b2a | |
| parent | fbd72c1c064047d8d1f988c79890c49f926aab95 (diff) | |
| download | mullvadvpn-7048540407083c7e557bac2419fbbb6d3433f868.tar.xz mullvadvpn-7048540407083c7e557bac2419fbbb6d3433f868.zip | |
SettingsCell: fix disclosure tint color on iOS 13 or newer
| -rw-r--r-- | ios/MullvadVPN/SettingsCell.swift | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/ios/MullvadVPN/SettingsCell.swift b/ios/MullvadVPN/SettingsCell.swift index 1d147242bf..fcda176f86 100644 --- a/ios/MullvadVPN/SettingsCell.swift +++ b/ios/MullvadVPN/SettingsCell.swift @@ -16,7 +16,6 @@ class SettingsCell: BasicTableViewCell { override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) - tintColor = .white backgroundView?.backgroundColor = UIColor.Cell.backgroundColor selectedBackgroundView?.backgroundColor = UIColor.Cell.selectedAltBackgroundColor separatorInset = .zero @@ -51,8 +50,6 @@ class SettingsCell: BasicTableViewCell { detailTitleLabel.topAnchor.constraint(equalTo: contentView.layoutMarginsGuide.topAnchor), detailTitleLabel.bottomAnchor.constraint(equalTo: contentView.layoutMarginsGuide.bottomAnchor), ]) - - enableDisclosureViewTintColorFix() } required init?(coder: NSCoder) { @@ -69,21 +66,8 @@ class SettingsCell: BasicTableViewCell { super.didAddSubview(subview) if let button = subview as? UIButton { - updateDisclosureButtonBackgroundImageRenderingMode(button) - } - } - - /// `UITableViewCell` resets the disclosure view image when the app goes in background - /// This fix ensures that the image is tinted when the app becomes active again. - private func enableDisclosureViewTintColorFix() { - appDidBecomeActiveObserver = NotificationCenter.default.addObserver( - forName: UIApplication.didBecomeActiveNotification, - object: nil, - queue: nil) { [weak self] (note) in - self?.updateDisclosureViewTintColor() + updateDisclosureIndicatorTintColor(button) } - - updateDisclosureViewTintColor() } private func setLayoutMargins() { @@ -94,17 +78,23 @@ class SettingsCell: BasicTableViewCell { contentView.layoutMargins = UIMetrics.settingsCellLayoutMargins } - /// For some reason the `tintColor` is not applied to standard accessory views. - /// Fix this by looking for the accessory button and changing the image rendering mode - private func updateDisclosureViewTintColor() { - for case let button as UIButton in subviews { - updateDisclosureButtonBackgroundImageRenderingMode(button) - } - } + /// Standard disclosure views do not provide customization of a tint color. + /// This method adjusts a disclosure tint color by replacing the button image rendering mode on iOS 12 and by + /// switching graphics on iOS 13 or newer. + private func updateDisclosureIndicatorTintColor(_ button: UIButton) { + guard accessoryType == .disclosureIndicator else { return } + + if #available(iOS 13, *) { + let configuration = UIImage.SymbolConfiguration(pointSize: 11, weight: .bold) + let chevron = UIImage(systemName: "chevron.right", withConfiguration: configuration)? + .withTintColor(.white, renderingMode: .alwaysOriginal) - private func updateDisclosureButtonBackgroundImageRenderingMode(_ button: UIButton) { - if let image = button.backgroundImage(for: .normal)?.withRenderingMode(.alwaysTemplate) { - button.setBackgroundImage(image, for: .normal) + button.setImage(chevron, for: .normal) + } else { + if let image = button.backgroundImage(for: .normal)?.withRenderingMode(.alwaysTemplate) { + button.setBackgroundImage(image, for: .normal) + button.tintColor = .white + } } } } |
