Messagekit: Dark Mode

Created on 26 Sep 2019  路  3Comments  路  Source: MessageKit/MessageKit

iOS 13 is out, and I can't figure out for the life of me how to change the CollectionView's background color to support dark mode.

Most helpful comment

Finally...

```swift
private func setupCollectionView() {
guard let flowLayout = messagesCollectionView.collectionViewLayout as? MessagesCollectionViewFlowLayout else {
print("Can't get flowLayout")
return
}
if #available(iOS 13.0, *) {
flowLayout.collectionView?.backgroundColor = .systemBackground
}
}
func inputStyle() {
if #available(iOS 13.0, *) {
messageInputBar.inputTextView.textColor = .label
messageInputBar.inputTextView.placeholderLabel.textColor = .secondaryLabel
messageInputBar.backgroundView.backgroundColor = .systemBackground
} else {
messageInputBar.inputTextView.textColor = .black
messageInputBar.inputTextView.backgroundColor = UIColor.rgb(red: 245, green: 245, blue: 245)
}
}

All 3 comments

Finally...

```swift
private func setupCollectionView() {
guard let flowLayout = messagesCollectionView.collectionViewLayout as? MessagesCollectionViewFlowLayout else {
print("Can't get flowLayout")
return
}
if #available(iOS 13.0, *) {
flowLayout.collectionView?.backgroundColor = .systemBackground
}
}
func inputStyle() {
if #available(iOS 13.0, *) {
messageInputBar.inputTextView.textColor = .label
messageInputBar.inputTextView.placeholderLabel.textColor = .secondaryLabel
messageInputBar.backgroundView.backgroundColor = .systemBackground
} else {
messageInputBar.inputTextView.textColor = .black
messageInputBar.inputTextView.backgroundColor = UIColor.rgb(red: 245, green: 245, blue: 245)
}
}

@nitrag could you please expaine where I should place this code?

@AlexeyShevchenko

internal class YourViewController: MessagesViewController

Don't forget to setup delegates

Was this page helpful?
0 / 5 - 0 ratings