瀏覽代碼

fix jumping date labels

cyberta 5 年之前
父節點
當前提交
df2b1bc8bd
共有 1 個文件被更改,包括 11 次插入5 次删除
  1. 11 5
      deltachat-ios/Controller/ChatViewController.swift

+ 11 - 5
deltachat-ios/Controller/ChatViewController.swift

@@ -773,13 +773,19 @@ extension ChatViewController: MessagesDataSource {
             return nil
             return nil
         }
         }
 
 
-        let timestampAttributes: [NSAttributedString.Key: Any] = [
+        var timestampAttributes: [NSAttributedString.Key: Any] = [
             .font: UIFont.systemFont(ofSize: 12),
             .font: UIFont.systemFont(ofSize: 12),
             .foregroundColor: UIColor.lightGray,
             .foregroundColor: UIColor.lightGray,
+            .paragraphStyle: NSParagraphStyle()
         ]
         ]
 
 
         if isFromCurrentSender(message: message) {
         if isFromCurrentSender(message: message) {
             let text = NSMutableAttributedString()
             let text = NSMutableAttributedString()
+            if let style = NSMutableParagraphStyle.default.mutableCopy() as? NSMutableParagraphStyle {
+                style.alignment = .right
+                timestampAttributes[.paragraphStyle] = style
+            }
+
             text.append(NSAttributedString(string: m.formattedSentDate(), attributes: timestampAttributes))
             text.append(NSAttributedString(string: m.formattedSentDate(), attributes: timestampAttributes))
 
 
             // TODO: this should be replaced by the respective icons,
             // TODO: this should be replaced by the respective icons,
@@ -810,10 +816,10 @@ extension ChatViewController: MessagesDataSource {
         }
         }
 
 
         if !isAvatarHidden(at: indexPath) {
         if !isAvatarHidden(at: indexPath) {
-            let text = NSMutableAttributedString()
-            text.append(NSAttributedString(string: "     "))
-            text.append(NSAttributedString(string: m.formattedSentDate(), attributes: timestampAttributes))
-            return text
+            if let style = NSMutableParagraphStyle.default.mutableCopy() as? NSMutableParagraphStyle {
+                style.firstLineHeadIndent = 22
+                timestampAttributes[.paragraphStyle] = style
+            }
         }
         }
 
 
         return NSAttributedString(string: m.formattedSentDate(), attributes: timestampAttributes)
         return NSAttributedString(string: m.formattedSentDate(), attributes: timestampAttributes)