Эх сурвалжийг харах

implement adaptive font sizes

cyberta 5 жил өмнө
parent
commit
e29e6d457b

+ 2 - 1
DcShare/View/ChatListCell.swift

@@ -15,7 +15,8 @@ class ChatListCell: UITableViewCell {
 
     let titleLabel: UILabel = {
         let label = UILabel()
-        label.font = UIFont.systemFont(ofSize: 16, weight: .medium)
+        label.font = UIFont.preferredFont(forTextStyle: .headline)
+        label.adjustsFontForContentSizeCategory = true
         label.lineBreakMode = .byTruncatingTail
         label.textColor = DcColors.defaultTextColor
         label.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 1), for: NSLayoutConstraint.Axis.horizontal)

+ 5 - 1
deltachat-ios/Controller/QrCodeReaderController.swift

@@ -21,6 +21,9 @@ class QrCodeReaderController: UIViewController {
         label.numberOfLines = 0
         label.textAlignment = .center
         label.textColor = .white
+        label.adjustsFontForContentSizeCategory = true
+        label.font = .preferredFont(forTextStyle: .subheadline)
+
         return label
     }()
 
@@ -85,8 +88,9 @@ class QrCodeReaderController: UIViewController {
         view.addSubview(infoLabel)
         infoLabel.translatesAutoresizingMaskIntoConstraints = false
 
-        infoLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
         infoLabel.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -10).isActive = true
+        infoLabel.constraintAlignLeadingTo(view, paddingLeading: 5).isActive = true
+        infoLabel.constraintAlignTrailingTo(view, paddingTrailing: 5).isActive = true
         view.bringSubviewToFront(infoLabel)
     }
 

+ 3 - 2
deltachat-ios/Controller/QrInviteViewController.swift

@@ -83,7 +83,7 @@ class QrInviteViewController: UITableViewController {
                                 label.constraintAlignTopTo(cell.contentView, paddingTop: 45),
                                 label.constraintAlignLeadingTo(cell.contentView, paddingLeading: 30),
                                 label.constraintAlignTrailingTo(cell.contentView, paddingTrailing: 30)]
-         cell.contentView.addConstraints(labelConstraints)
+        cell.contentView.addConstraints(labelConstraints)
         return cell
     }
 
@@ -114,7 +114,8 @@ class QrInviteViewController: UITableViewController {
         label.lineBreakMode = .byWordWrapping
         label.numberOfLines = 0
         label.textAlignment = .center
-        label.font = UIFont.systemFont(ofSize: 14)
+        label.font = UIFont.preferredFont(forTextStyle: .subheadline)
+        label.adjustsFontForContentSizeCategory = true
         return label
     }
 }

+ 2 - 1
deltachat-ios/Controller/QrViewController.swift

@@ -100,7 +100,8 @@ class QrViewContentView: UIView {
         label.lineBreakMode = .byWordWrapping
         label.numberOfLines = 0
         label.textAlignment = .center
-        label.font = UIFont.systemFont(ofSize: 14)
+        label.font = .preferredFont(forTextStyle: .subheadline)
+        label.adjustsFontForContentSizeCategory = true
         return label
     }()
 

+ 6 - 0
deltachat-ios/Extensions/String+Extension.swift

@@ -74,6 +74,12 @@ extension String {
         return attributedText
     }
 
+    func bold(fontSize: CGFloat) -> NSAttributedString {
+        let attributedText = NSMutableAttributedString(string: self)
+        attributedText.addAttribute(.font, value: UIFont.boldSystemFont(ofSize: fontSize), range: NSRange(location: 0, length: count - 1))
+        return attributedText
+    }
+
     static func timeStringForInterval(_ interval: TimeInterval) -> String {
         let time = NSInteger(interval)
         let seconds = time % 60

+ 2 - 1
deltachat-ios/MessageKit/Views/AudioPlayerView.swift

@@ -19,7 +19,8 @@ open class AudioPlayerView: UIView {
     private lazy var durationLabel: UILabel = {
         let durationLabel = UILabel(frame: CGRect.zero)
         durationLabel.textAlignment = .right
-        durationLabel.font = UIFont.systemFont(ofSize: 14)
+        durationLabel.font = UIFont.preferredFont(forTextStyle: .body)
+        durationLabel.adjustsFontForContentSizeCategory = true
         durationLabel.text = "0:00"
         durationLabel.translatesAutoresizingMaskIntoConstraints = false
         return durationLabel

+ 3 - 0
deltachat-ios/View/ActionCell.swift

@@ -22,6 +22,9 @@ class ActionCell: UITableViewCell {
         let label = UILabel()
         label.text = actionTitle
         label.textColor = UIColor.systemBlue
+        label.font = .preferredFont(forTextStyle: .body)
+        label.adjustsFontForContentSizeCategory = true
+        label.lineBreakMode = .byTruncatingTail
         return label
     }()
 

+ 2 - 0
deltachat-ios/View/AvatarSelectionCell.swift

@@ -25,6 +25,8 @@ class AvatarSelectionCell: UITableViewCell {
         label.translatesAutoresizingMaskIntoConstraints = false
         label.textColor = DcColors.defaultTextColor
         label.text = String.localized("pref_profile_photo")
+        label.font = .preferredFont(forTextStyle: .body)
+        label.adjustsFontForContentSizeCategory = true
         return label
     }()
 

+ 17 - 7
deltachat-ios/View/ContactCell.swift

@@ -26,6 +26,7 @@ class ContactCell: UITableViewCell {
         let stackView = UIStackView(arrangedSubviews: [subtitleLabel, deliveryStatusIndicator, archivedIndicator, unreadMessageCounter])
         stackView.axis = .horizontal
         stackView.spacing = 10
+        stackView.alignment = .firstBaseline
         return stackView
     }()
 
@@ -38,38 +39,40 @@ class ContactCell: UITableViewCell {
 
     let titleLabel: UILabel = {
         let label = UILabel()
-        label.font = UIFont.systemFont(ofSize: 16, weight: .medium)
         label.lineBreakMode = .byTruncatingTail
         label.textColor = DcColors.defaultTextColor
         label.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 1), for: NSLayoutConstraint.Axis.horizontal)
+        label.font = UIFont.preferredFont(forTextStyle: .body)
+        label.adjustsFontForContentSizeCategory = true
         return label
     }()
 
     private let pinnedIndicator: UIImageView = {
         let view = UIImageView()
         view.translatesAutoresizingMaskIntoConstraints = false
-        view.heightAnchor.constraint(equalToConstant: 16).isActive = true
         view.widthAnchor.constraint(equalToConstant: 16).isActive = true
         view.tintColor = DcColors.middleGray
         view.image = #imageLiteral(resourceName: "pinned_chatlist").withRenderingMode(.alwaysTemplate)
         view.isHidden = true
+        view.contentMode = .scaleAspectFit
         return view
     }()
 
     private let mutedIndicator: UIImageView = {
         let view = UIImageView()
         view.translatesAutoresizingMaskIntoConstraints = false
-        view.heightAnchor.constraint(equalToConstant: 16).isActive = true
         view.widthAnchor.constraint(equalToConstant: 16).isActive = true
         view.tintColor = DcColors.middleGray
         view.image = #imageLiteral(resourceName: "volume_off").withRenderingMode(.alwaysTemplate)
         view.isHidden = true
+        view.contentMode = .scaleAspectFit
         return view
     }()
 
     private let timeLabel: UILabel = {
         let label = UILabel()
-        label.font = UIFont.systemFont(ofSize: 14)
+        label.font = UIFont.preferredFont(forTextStyle: .subheadline)
+        label.adjustsFontForContentSizeCategory = true
         label.textColor = DcColors.middleGray
         label.textAlignment = .right
         label.setContentHuggingPriority(.defaultHigh, for: NSLayoutConstraint.Axis.horizontal)
@@ -80,20 +83,21 @@ class ContactCell: UITableViewCell {
     private let locationStreamingIndicator: UIImageView = {
         let view = UIImageView()
         view.translatesAutoresizingMaskIntoConstraints = false
-        view.heightAnchor.constraint(equalToConstant: 16).isActive = true
         view.widthAnchor.constraint(equalToConstant: 16).isActive = true
         view.tintColor = DcColors.checkmarkGreen
         view.image = #imageLiteral(resourceName: "ic_location").withRenderingMode(.alwaysTemplate)
         view.isHidden = true
+        view.contentMode = .scaleAspectFit
         return view
     }()
 
     let subtitleLabel: UILabel = {
         let label = UILabel()
-        label.font = UIFont.systemFont(ofSize: 14)
         label.textColor = DcColors.middleGray
         label.lineBreakMode = .byTruncatingTail
         label.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 1), for: NSLayoutConstraint.Axis.horizontal)
+        label.font = .preferredFont(forTextStyle: .subheadline)
+        label.adjustsFontForContentSizeCategory = true
         return label
     }()
 
@@ -170,6 +174,12 @@ class ContactCell: UITableViewCell {
         verticalStackView.axis = .vertical
         verticalStackView.addArrangedSubview(toplineStackView)
         verticalStackView.addArrangedSubview(bottomlineStackView)
+
+        toplineStackView.addConstraints([
+            pinnedIndicator.constraintHeightTo(titleLabel.font.fontDescriptor.pointSize * 1.2),
+            mutedIndicator.constraintHeightTo(titleLabel.font.fontDescriptor.pointSize * 1.2),
+            locationStreamingIndicator.constraintHeightTo(titleLabel.font.fontDescriptor.pointSize * 1.2)
+        ])
     }
 
     func setVerified(isVerified: Bool) {
@@ -267,7 +277,7 @@ class ContactCell: UITableViewCell {
 
             // text bold if chat contains unread messages - otherwise hightlight search results if needed
             if chatData.unreadMessages > 0 {
-                titleLabel.attributedText = NSAttributedString(string: cellViewModel.title, attributes: [ .font: UIFont.systemFont(ofSize: 16, weight: .bold) ])
+                titleLabel.attributedText = cellViewModel.title.bold(fontSize: titleLabel.font.pointSize)
             } else {
                 titleLabel.attributedText = cellViewModel.title.boldAt(indexes: cellViewModel.titleHighlightIndexes, fontSize: titleLabel.font.pointSize)
             }

+ 4 - 2
deltachat-ios/View/ContactDetailHeader.swift

@@ -16,18 +16,20 @@ class ContactDetailHeader: UIView {
 
     private var titleLabel: UILabel = {
         let label = UILabel()
-        label.font = UIFont.systemFont(ofSize: 16, weight: .medium)
         label.lineBreakMode = .byTruncatingTail
         label.textColor = DcColors.defaultTextColor
         label.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 1), for: NSLayoutConstraint.Axis.horizontal)
+        label.adjustsFontForContentSizeCategory = true
+        label.font = .preferredFont(forTextStyle: UIFont.TextStyle.headline)
         return label
     }()
 
     private var subtitleLabel: UILabel = {
         let label = UILabel()
-        label.font = UIFont.systemFont(ofSize: 14)
+        label.font = .preferredFont(forTextStyle: .callout)
         label.textColor = UIColor(hexString: "848ba7")
         label.lineBreakMode = .byTruncatingTail
+        label.adjustsFontForContentSizeCategory = true
         return label
     }()
 

+ 13 - 4
deltachat-ios/View/MultilineTextFieldCell.swift

@@ -2,7 +2,11 @@ import Foundation
 import UIKit
 
 class MultilineTextFieldCell: UITableViewCell, UITextViewDelegate {
-    static let cellHeight: CGFloat = 125
+
+    private static let padding: CGFloat = 16
+    static var cellHeight: CGFloat {
+        return UIFont.preferredFont(forTextStyle: .body).fontDescriptor.pointSize * 6 + MultilineTextFieldCell.padding
+    }
 
     var onTextFieldChange:((_:UITextView) -> Void)?    // set this from outside to get notified about textfield changes
 
@@ -10,6 +14,8 @@ class MultilineTextFieldCell: UITableViewCell, UITextViewDelegate {
         let textField = UITextField()
         textField.translatesAutoresizingMaskIntoConstraints = false
         textField.isEnabled = false
+        textField.adjustsFontForContentSizeCategory = true
+        textField.font = .preferredFont(forTextStyle: .body)
         return textField
     }()
 
@@ -17,16 +23,18 @@ class MultilineTextFieldCell: UITableViewCell, UITextViewDelegate {
         let textField = UITextView()
         textField.delegate = self
         textField.translatesAutoresizingMaskIntoConstraints = false
-        textField.font = UIFont.systemFont(ofSize: 16)
+        textField.adjustsFontForContentSizeCategory = true
+        textField.font = .preferredFont(forTextStyle: .body)
         textField.backgroundColor = .none
         return textField
     }()
 
     lazy var placeholder: UILabel = {
         let placeholderLabel = UILabel()
-        placeholderLabel.font = self.textField.font
         placeholderLabel.textColor = UIColor.lightGray
         placeholderLabel.translatesAutoresizingMaskIntoConstraints = false
+        placeholderLabel.adjustsFontForContentSizeCategory = true
+        placeholderLabel.font = .preferredFont(forTextStyle: .body)
         return placeholderLabel
     }()
 
@@ -56,7 +64,8 @@ class MultilineTextFieldCell: UITableViewCell, UITextViewDelegate {
 
         textField.alignLeadingToAnchor(margins.leadingAnchor, paddingLeading: -5)
         textField.alignTrailingToAnchor(margins.trailingAnchor)
-        contentView.addConstraint(textField.constraintHeightTo(95))
+        let fontsize = textField.font!.fontDescriptor.pointSize
+        contentView.addConstraint(textField.constraintHeightTo(fontsize * 4))
         textField.alignTopToAnchor(descriptionField.bottomAnchor)
 
         placeholder.alignLeadingToAnchor(margins.leadingAnchor)

+ 2 - 0
deltachat-ios/View/TextFieldCell.swift

@@ -18,6 +18,8 @@ class TextFieldCell: UITableViewCell {
         textField.textAlignment = .right
         // textField.enablesReturnKeyAutomatically = true
         textField.addTarget(self, action: #selector(textFieldChanged), for: .editingChanged)
+        textField.adjustsFontForContentSizeCategory = true
+        textField.font = .preferredFont(forTextStyle: .body)
         return textField
     }()