UI: iOS: adjust colors for iOS 13

To be compatible with Dark Mode, we need to change some of our
color references to be "dynamic".

Signed-off-by: Diab Neiroukh <officiallazerl0rd@gmail.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Diab Neiroukh 2019-10-14 22:43:56 +01:00 committed by Jason A. Donenfeld
parent 226166bdaf
commit 4c37a4b7a7
9 changed files with 70 additions and 20 deletions

View File

@ -9,8 +9,8 @@ class ButtonCell: UITableViewCell {
set(value) { button.setTitle(value, for: .normal) } set(value) { button.setTitle(value, for: .normal) }
} }
var hasDestructiveAction: Bool { var hasDestructiveAction: Bool {
get { return button.tintColor == .red } get { return button.tintColor == .systemRed }
set(value) { button.tintColor = value ? .red : buttonStandardTintColor } set(value) { button.tintColor = value ? .systemRed : buttonStandardTintColor }
} }
var onTapped: (() -> Void)? var onTapped: (() -> Void)?

View File

@ -9,7 +9,11 @@ class KeyValueCell: UITableViewCell {
let keyLabel = UILabel() let keyLabel = UILabel()
keyLabel.font = UIFont.preferredFont(forTextStyle: .body) keyLabel.font = UIFont.preferredFont(forTextStyle: .body)
keyLabel.adjustsFontForContentSizeCategory = true keyLabel.adjustsFontForContentSizeCategory = true
if #available(iOS 13.0, *) {
keyLabel.textColor = .label
} else {
keyLabel.textColor = .black keyLabel.textColor = .black
}
keyLabel.textAlignment = .left keyLabel.textAlignment = .left
return keyLabel return keyLabel
}() }()
@ -31,7 +35,11 @@ class KeyValueCell: UITableViewCell {
valueTextField.autocapitalizationType = .none valueTextField.autocapitalizationType = .none
valueTextField.autocorrectionType = .no valueTextField.autocorrectionType = .no
valueTextField.spellCheckingType = .no valueTextField.spellCheckingType = .no
if #available(iOS 13.0, *) {
valueTextField.textColor = .secondaryLabel
} else {
valueTextField.textColor = .gray valueTextField.textColor = .gray
}
return valueTextField return valueTextField
}() }()
@ -56,6 +64,13 @@ class KeyValueCell: UITableViewCell {
var isValueValid = true { var isValueValid = true {
didSet { didSet {
if #available(iOS 13.0, *) {
if isValueValid {
keyLabel.textColor = .label
} else {
keyLabel.textColor = .systemRed
}
} else {
if isValueValid { if isValueValid {
keyLabel.textColor = .black keyLabel.textColor = .black
} else { } else {
@ -63,6 +78,7 @@ class KeyValueCell: UITableViewCell {
} }
} }
} }
}
var isStackedHorizontally = false var isStackedHorizontally = false
var isStackedVertically = false var isStackedVertically = false

View File

@ -16,9 +16,13 @@ class SwitchCell: UITableViewCell {
get { return switchView.isEnabled } get { return switchView.isEnabled }
set(value) { set(value) {
switchView.isEnabled = value switchView.isEnabled = value
if #available(iOS 13.0, *) {
textLabel?.textColor = value ? .label : .secondaryLabel
} else {
textLabel?.textColor = value ? .black : .gray textLabel?.textColor = value ? .black : .gray
} }
} }
}
var onSwitchToggled: ((Bool) -> Void)? var onSwitchToggled: ((Bool) -> Void)?

View File

@ -28,7 +28,11 @@ class TextCell: UITableViewCell {
override func prepareForReuse() { override func prepareForReuse() {
super.prepareForReuse() super.prepareForReuse()
message = "" message = ""
if #available(iOS 13.0, *) {
setTextColor(.label)
} else {
setTextColor(.black) setTextColor(.black)
}
setTextAlignment(.left) setTextAlignment(.left)
} }
} }

View File

@ -30,7 +30,11 @@ class TunnelEditEditableKeyValueCell: TunnelEditKeyValueCell {
super.init(style: style, reuseIdentifier: reuseIdentifier) super.init(style: style, reuseIdentifier: reuseIdentifier)
copyableGesture = false copyableGesture = false
if #available(iOS 13.0, *) {
valueTextField.textColor = .label
} else {
valueTextField.textColor = .black valueTextField.textColor = .black
}
valueTextField.isEnabled = true valueTextField.isEnabled = true
valueLabelScrollView.isScrollEnabled = false valueLabelScrollView.isScrollEnabled = false
valueTextField.widthAnchor.constraint(equalTo: valueLabelScrollView.widthAnchor).isActive = true valueTextField.widthAnchor.constraint(equalTo: valueLabelScrollView.widthAnchor).isActive = true

View File

@ -29,9 +29,15 @@ class TunnelListCell: UITableViewCell {
}() }()
let busyIndicator: UIActivityIndicatorView = { let busyIndicator: UIActivityIndicatorView = {
if #available(iOS 13.0, *) {
let busyIndicator = UIActivityIndicatorView(style: .medium)
busyIndicator.hidesWhenStopped = true
return busyIndicator
} else {
let busyIndicator = UIActivityIndicatorView(style: .gray) let busyIndicator = UIActivityIndicatorView(style: .gray)
busyIndicator.hidesWhenStopped = true busyIndicator.hidesWhenStopped = true
return busyIndicator return busyIndicator
}
}() }()
let statusSwitch = UISwitch() let statusSwitch = UISwitch()

View File

@ -15,9 +15,15 @@ class LogViewController: UIViewController {
}() }()
let busyIndicator: UIActivityIndicatorView = { let busyIndicator: UIActivityIndicatorView = {
if #available(iOS 13.0, *) {
let busyIndicator = UIActivityIndicatorView(style: .medium)
busyIndicator.hidesWhenStopped = true
return busyIndicator
} else {
let busyIndicator = UIActivityIndicatorView(style: .gray) let busyIndicator = UIActivityIndicatorView(style: .gray)
busyIndicator.hidesWhenStopped = true busyIndicator.hidesWhenStopped = true
return busyIndicator return busyIndicator
}
}() }()
let paragraphStyle: NSParagraphStyle = { let paragraphStyle: NSParagraphStyle = {

View File

@ -176,7 +176,11 @@ extension SSIDOptionEditTableViewController {
private func noSSIDsCell(for tableView: UITableView, at indexPath: IndexPath) -> UITableViewCell { private func noSSIDsCell(for tableView: UITableView, at indexPath: IndexPath) -> UITableViewCell {
let cell: TextCell = tableView.dequeueReusableCell(for: indexPath) let cell: TextCell = tableView.dequeueReusableCell(for: indexPath)
cell.message = tr("tunnelOnDemandNoSSIDs") cell.message = tr("tunnelOnDemandNoSSIDs")
if #available(iOS 13.0, *) {
cell.setTextColor(.secondaryLabel)
} else {
cell.setTextColor(.gray) cell.setTextColor(.gray)
}
cell.setTextAlignment(.center) cell.setTextAlignment(.center)
return cell return cell
} }

View File

@ -32,9 +32,15 @@ class TunnelsListTableViewController: UIViewController {
}() }()
let busyIndicator: UIActivityIndicatorView = { let busyIndicator: UIActivityIndicatorView = {
if #available(iOS 13.0, *) {
let busyIndicator = UIActivityIndicatorView(style: .medium)
busyIndicator.hidesWhenStopped = true
return busyIndicator
} else {
let busyIndicator = UIActivityIndicatorView(style: .gray) let busyIndicator = UIActivityIndicatorView(style: .gray)
busyIndicator.hidesWhenStopped = true busyIndicator.hidesWhenStopped = true
return busyIndicator return busyIndicator
}
}() }()
var detailDisplayedTunnel: TunnelContainer? var detailDisplayedTunnel: TunnelContainer?