瀏覽代碼

add default background view to chats

cyberta 3 年之前
父節點
當前提交
d7be4678e7
共有 1 個文件被更改,包括 15 次插入0 次删除
  1. 15 0
      deltachat-ios/Chat/ChatViewController.swift

+ 15 - 0
deltachat-ios/Chat/ChatViewController.swift

@@ -64,6 +64,17 @@ class ChatViewController: UITableViewController {
         return view
         return view
     }()
     }()
 
 
+    public lazy var backgroundContainer: UIImageView = {
+        let view = UIImageView()
+        view.contentMode = .scaleAspectFill
+        if #available(iOS 12.0, *) {
+            view.image = UIImage(named: traitCollection.userInterfaceStyle == .light ? "background_light" : "background_dark")
+        } else {
+            view.image = UIImage(named: "background_light")
+        }
+        return view
+    }()
+
     /// The `InputBarAccessoryView` used as the `inputAccessoryView` in the view controller.
     /// The `InputBarAccessoryView` used as the `inputAccessoryView` in the view controller.
     open var messageInputBar = ChatInputBar()
     open var messageInputBar = ChatInputBar()
 
 
@@ -274,6 +285,7 @@ class ChatViewController: UITableViewController {
 
 
     override func viewDidLoad() {
     override func viewDidLoad() {
         super.viewDidLoad()
         super.viewDidLoad()
+        tableView.backgroundView = backgroundContainer
         tableView.register(TextMessageCell.self, forCellReuseIdentifier: "text")
         tableView.register(TextMessageCell.self, forCellReuseIdentifier: "text")
         tableView.register(ImageTextCell.self, forCellReuseIdentifier: "image")
         tableView.register(ImageTextCell.self, forCellReuseIdentifier: "image")
         tableView.register(FileTextCell.self, forCellReuseIdentifier: "file")
         tableView.register(FileTextCell.self, forCellReuseIdentifier: "file")
@@ -841,6 +853,9 @@ class ChatViewController: UITableViewController {
     
     
     override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
     override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
         messageInputBar.inputTextView.layer.borderColor = DcColors.colorDisabled.cgColor
         messageInputBar.inputTextView.layer.borderColor = DcColors.colorDisabled.cgColor
+        if #available(iOS 12.0, *) {
+            backgroundContainer.image = UIImage(named: traitCollection.userInterfaceStyle == .light ? "background_light" : "background_dark")
+        }
     }
     }
 
 
     func configureMessageStyle(for message: DcMsg, at indexPath: IndexPath) -> UIRectCorner {
     func configureMessageStyle(for message: DcMsg, at indexPath: IndexPath) -> UIRectCorner {