From d7ce621cb2d1c4a91844ac1111e7c041c58dec8e Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 25 Oct 2019 10:59:16 +0200 Subject: [PATCH] UI: iOS: more dark mode fixes Signed-off-by: Jason A. Donenfeld --- WireGuard/WireGuard/UI/iOS/AppDelegate.swift | 6 ++++- .../ViewController/LogViewController.swift | 22 ++++++++++++++----- .../ViewController/MainViewController.swift | 6 ++++- .../TunnelsListTableViewController.swift | 12 ++++++++-- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/WireGuard/WireGuard/UI/iOS/AppDelegate.swift b/WireGuard/WireGuard/UI/iOS/AppDelegate.swift index 41a136e..418557e 100644 --- a/WireGuard/WireGuard/UI/iOS/AppDelegate.swift +++ b/WireGuard/WireGuard/UI/iOS/AppDelegate.swift @@ -21,7 +21,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate { } let window = UIWindow(frame: UIScreen.main.bounds) - window.backgroundColor = .white + if #available(iOS 13.0, *) { + window.backgroundColor = .systemBackground + } else { + window.backgroundColor = .white + } self.window = window let mainVC = MainViewController() diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/LogViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/LogViewController.swift index 25c16b0..f31af01 100644 --- a/WireGuard/WireGuard/UI/iOS/ViewController/LogViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/ViewController/LogViewController.swift @@ -41,7 +41,11 @@ class LogViewController: UIViewController { override func loadView() { view = UIView() - view.backgroundColor = .white + if #available(iOS 13.0, *) { + view.backgroundColor = .systemBackground + } else { + view.backgroundColor = .white + } view.addSubview(textView) textView.translatesAutoresizingMaskIntoConstraints = false @@ -87,12 +91,18 @@ class LogViewController: UIViewController { let richText = NSMutableAttributedString() let bodyFont = UIFont.preferredFont(forTextStyle: UIFont.TextStyle.body) let captionFont = UIFont.preferredFont(forTextStyle: UIFont.TextStyle.caption1) - let lightGrayColor = UIColor(white: 0.88, alpha: 1.0) - for logEntry in fetchedLogEntries { - let bgColor = self.isNextLineHighlighted ? lightGrayColor : UIColor.white - let timestampText = NSAttributedString(string: logEntry.timestamp + "\n", attributes: [.font: captionFont, .backgroundColor: bgColor, .paragraphStyle: self.paragraphStyle]) - let messageText = NSAttributedString(string: logEntry.message + "\n", attributes: [.font: bodyFont, .backgroundColor: bgColor, .paragraphStyle: self.paragraphStyle]) + var bgColor: UIColor + var fgColor: UIColor + if #available(iOS 13.0, *) { + bgColor = self.isNextLineHighlighted ? .systemGray3 : .systemBackground + fgColor = .label + } else { + bgColor = self.isNextLineHighlighted ? UIColor(white: 0.88, alpha: 1.0) : UIColor.white + fgColor = .black + } + let timestampText = NSAttributedString(string: logEntry.timestamp + "\n", attributes: [.font: captionFont, .backgroundColor: bgColor, .foregroundColor: fgColor, .paragraphStyle: self.paragraphStyle]) + let messageText = NSAttributedString(string: logEntry.message + "\n", attributes: [.font: bodyFont, .backgroundColor: bgColor, .foregroundColor: fgColor, .paragraphStyle: self.paragraphStyle]) richText.append(timestampText) richText.append(messageText) self.isNextLineHighlighted.toggle() diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/MainViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/MainViewController.swift index b37a4d4..514e037 100644 --- a/WireGuard/WireGuard/UI/iOS/ViewController/MainViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/ViewController/MainViewController.swift @@ -11,7 +11,11 @@ class MainViewController: UISplitViewController { init() { let detailVC = UIViewController() - detailVC.view.backgroundColor = .white + if #available(iOS 13.0, *) { + detailVC.view.backgroundColor = .systemBackground + } else { + detailVC.view.backgroundColor = .white + } let detailNC = UINavigationController(rootViewController: detailVC) let masterVC = TunnelsListTableViewController() diff --git a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift index 58d98c9..e805db5 100644 --- a/WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift +++ b/WireGuard/WireGuard/UI/iOS/ViewController/TunnelsListTableViewController.swift @@ -52,7 +52,11 @@ class TunnelsListTableViewController: UIViewController { override func loadView() { view = UIView() - view.backgroundColor = .white + if #available(iOS 13.0, *) { + view.backgroundColor = .systemBackground + } else { + view.backgroundColor = .white + } tableView.dataSource = self tableView.delegate = self @@ -395,7 +399,11 @@ extension TunnelsListTableViewController: TunnelsManagerListDelegate { (splitViewController.viewControllers[0] as? UINavigationController)?.popToRootViewController(animated: false) } else { let detailVC = UIViewController() - detailVC.view.backgroundColor = .white + if #available(iOS 13.0, *) { + detailVC.view.backgroundColor = .systemBackground + } else { + detailVC.view.backgroundColor = .white + } let detailNC = UINavigationController(rootViewController: detailVC) splitViewController.showDetailViewController(detailNC, sender: self) }