diff --git a/Example/Sources/View Controllers/AdvancedExampleViewController.swift b/Example/Sources/View Controllers/AdvancedExampleViewController.swift index 98081c1c..33db3654 100644 --- a/Example/Sources/View Controllers/AdvancedExampleViewController.swift +++ b/Example/Sources/View Controllers/AdvancedExampleViewController.swift @@ -279,6 +279,19 @@ final class AdvancedExampleViewController: ChatViewController { return nil } + override func messageTimestampLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? { + let sentDate = message.sentDate + let sentDateString = MessageKitDateFormatter.shared.string(from: sentDate) + let timeLabelFont: UIFont = .boldSystemFont(ofSize: 10) + let timeLabelColor: UIColor + if #available(iOS 13, *) { + timeLabelColor = .systemGray + } else { + timeLabelColor = .darkGray + } + return NSAttributedString(string: sentDateString, attributes: [NSAttributedString.Key.font: timeLabelFont, NSAttributedString.Key.foregroundColor: timeLabelColor]) + } + } // MARK: - MessagesDisplayDelegate diff --git a/Example/Sources/View Controllers/AutocompleteExampleViewController.swift b/Example/Sources/View Controllers/AutocompleteExampleViewController.swift index f50090aa..47804300 100644 --- a/Example/Sources/View Controllers/AutocompleteExampleViewController.swift +++ b/Example/Sources/View Controllers/AutocompleteExampleViewController.swift @@ -187,6 +187,19 @@ final class AutocompleteExampleViewController: ChatViewController { return nil } + override func messageTimestampLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? { + let sentDate = message.sentDate + let sentDateString = MessageKitDateFormatter.shared.string(from: sentDate) + let timeLabelFont: UIFont = .boldSystemFont(ofSize: 10) + let timeLabelColor: UIColor + if #available(iOS 13, *) { + timeLabelColor = .systemGray + } else { + timeLabelColor = .darkGray + } + return NSAttributedString(string: sentDateString, attributes: [NSAttributedString.Key.font: timeLabelFont, NSAttributedString.Key.foregroundColor: timeLabelColor]) + } + // Async autocomplete requires the manager to reload func inputBar(_ inputBar: InputBarAccessoryView, textViewTextDidChangeTo text: String) { guard autocompleteManager.currentSession != nil, autocompleteManager.currentSession?.prefix == "#" else { return } diff --git a/Sources/Protocols/MessagesDataSource.swift b/Sources/Protocols/MessagesDataSource.swift index 4b1e3746..0139f278 100644 --- a/Sources/Protocols/MessagesDataSource.swift +++ b/Sources/Protocols/MessagesDataSource.swift @@ -159,7 +159,20 @@ public extension MessagesDataSource { func messageBottomLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? { return nil } - + + func messageTimestampLabelAttributedText(for message: MessageType, at indexPath: IndexPath) -> NSAttributedString? { + let sentDate = message.sentDate + let sentDateString = MessageKitDateFormatter.shared.string(from: sentDate) + let timeLabelFont: UIFont = .boldSystemFont(ofSize: 10) + let timeLabelColor: UIColor + if #available(iOS 13, *) { + timeLabelColor = .systemGray + } else { + timeLabelColor = .darkGray + } + return NSAttributedString(string: sentDateString, attributes: [NSAttributedString.Key.font: timeLabelFont, NSAttributedString.Key.foregroundColor: timeLabelColor]) + } + func customCell(for message: MessageType, at indexPath: IndexPath, in messagesCollectionView: MessagesCollectionView) -> UICollectionViewCell { fatalError(MessageKitError.customDataUnresolvedCell) }