diff --git a/Mastodon/Scene/Compose/View/AttachmentContainerView.swift b/Mastodon/Scene/Compose/View/AttachmentContainerView.swift index cbad7683..eb5f01f4 100644 --- a/Mastodon/Scene/Compose/View/AttachmentContainerView.swift +++ b/Mastodon/Scene/Compose/View/AttachmentContainerView.swift @@ -47,7 +47,7 @@ final class AttachmentContainerView: UIView { textView.showsVerticalScrollIndicator = false textView.backgroundColor = .clear textView.textColor = .white - textView.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 15)) + textView.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 15), maximumPointSize: 20) textView.placeholder = L10n.Scene.Compose.Attachment.descriptionPhoto textView.placeholderColor = UIColor.white.withAlphaComponent(0.6) // force white with alpha for Light/Dark mode textView.returnKeyType = .done diff --git a/Mastodon/Scene/Notification/TableViewCell/NotificationStatusTableViewCell.swift b/Mastodon/Scene/Notification/TableViewCell/NotificationStatusTableViewCell.swift index 7b76dd2f..5ae5d013 100644 --- a/Mastodon/Scene/Notification/TableViewCell/NotificationStatusTableViewCell.swift +++ b/Mastodon/Scene/Notification/TableViewCell/NotificationStatusTableViewCell.swift @@ -50,7 +50,7 @@ final class NotificationStatusTableViewCell: UITableViewCell, StatusCell { let actionLabel: UILabel = { let label = UILabel() label.textColor = Asset.Colors.Label.secondary.color - label.font = UIFont.preferredFont(forTextStyle: .body) + label.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 15, weight: .regular), maximumPointSize: 20) label.lineBreakMode = .byTruncatingTail return label }() @@ -58,7 +58,7 @@ final class NotificationStatusTableViewCell: UITableViewCell, StatusCell { let nameLabel: UILabel = { let label = UILabel() label.textColor = Asset.Colors.brandBlue.color - label.font = .systemFont(ofSize: 15, weight: .semibold) + label.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 15, weight: .semibold), maximumPointSize: 20) label.lineBreakMode = .byTruncatingTail return label }() diff --git a/Mastodon/Scene/Notification/TableViewCell/NotificationTableViewCell.swift b/Mastodon/Scene/Notification/TableViewCell/NotificationTableViewCell.swift index c049b961..49d32530 100644 --- a/Mastodon/Scene/Notification/TableViewCell/NotificationTableViewCell.swift +++ b/Mastodon/Scene/Notification/TableViewCell/NotificationTableViewCell.swift @@ -67,7 +67,7 @@ final class NotificationTableViewCell: UITableViewCell { let actionLabel: UILabel = { let label = UILabel() label.textColor = Asset.Colors.Label.secondary.color - label.font = UIFont.preferredFont(forTextStyle: .body) + label.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 15, weight: .regular), maximumPointSize: 20) label.lineBreakMode = .byTruncatingTail return label }() @@ -75,7 +75,7 @@ final class NotificationTableViewCell: UITableViewCell { let nameLabel: UILabel = { let label = UILabel() label.textColor = Asset.Colors.brandBlue.color - label.font = .systemFont(ofSize: 15, weight: .semibold) + label.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 15, weight: .semibold), maximumPointSize: 20) label.lineBreakMode = .byTruncatingTail return label }() diff --git a/Mastodon/Scene/Onboarding/PickServer/TableViewCell/PickServerCell.swift b/Mastodon/Scene/Onboarding/PickServer/TableViewCell/PickServerCell.swift index 9313aa5c..85c998b8 100644 --- a/Mastodon/Scene/Onboarding/PickServer/TableViewCell/PickServerCell.swift +++ b/Mastodon/Scene/Onboarding/PickServer/TableViewCell/PickServerCell.swift @@ -34,7 +34,7 @@ class PickServerCell: UITableViewCell { let domainLabel: UILabel = { let label = UILabel() - label.font = .preferredFont(forTextStyle: .headline) + label.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold), maximumPointSize: 22) label.textColor = Asset.Colors.Label.primary.color label.adjustsFontForContentSizeCategory = true label.translatesAutoresizingMaskIntoConstraints = false @@ -52,7 +52,7 @@ class PickServerCell: UITableViewCell { let descriptionLabel: UILabel = { let label = UILabel() - label.font = .preferredFont(forTextStyle: .subheadline) + label.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 15, weight: .regular)) label.numberOfLines = 0 label.textColor = Asset.Colors.Label.primary.color label.adjustsFontForContentSizeCategory = true @@ -106,7 +106,7 @@ class PickServerCell: UITableViewCell { let langValueLabel: UILabel = { let label = UILabel() label.textColor = Asset.Colors.Label.primary.color - label.font = UIFontMetrics(forTextStyle: .title2).scaledFont(for: UIFont.systemFont(ofSize: 22, weight: .semibold)) + label.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 22, weight: .semibold), maximumPointSize: 27) label.textAlignment = .center label.adjustsFontForContentSizeCategory = true label.translatesAutoresizingMaskIntoConstraints = false @@ -116,7 +116,7 @@ class PickServerCell: UITableViewCell { let usersValueLabel: UILabel = { let label = UILabel() label.textColor = Asset.Colors.Label.primary.color - label.font = UIFontMetrics(forTextStyle: .title2).scaledFont(for: UIFont.systemFont(ofSize: 22, weight: .semibold)) + label.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 22, weight: .semibold), maximumPointSize: 27) label.textAlignment = .center label.adjustsFontForContentSizeCategory = true label.translatesAutoresizingMaskIntoConstraints = false @@ -126,7 +126,7 @@ class PickServerCell: UITableViewCell { let categoryValueLabel: UILabel = { let label = UILabel() label.textColor = Asset.Colors.Label.primary.color - label.font = UIFontMetrics(forTextStyle: .title2).scaledFont(for: UIFont.systemFont(ofSize: 22, weight: .semibold)) + label.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 22, weight: .semibold), maximumPointSize: 27) label.textAlignment = .center label.adjustsFontForContentSizeCategory = true label.translatesAutoresizingMaskIntoConstraints = false @@ -136,7 +136,7 @@ class PickServerCell: UITableViewCell { let langTitleLabel: UILabel = { let label = UILabel() label.textColor = Asset.Colors.Label.primary.color - label.font = .preferredFont(forTextStyle: .caption2) + label.font = UIFontMetrics(forTextStyle: .subheadline).scaledFont(for: .systemFont(ofSize: 11, weight: .regular), maximumPointSize: 16) label.text = L10n.Scene.ServerPicker.Label.language label.textAlignment = .center label.adjustsFontForContentSizeCategory = true @@ -147,7 +147,7 @@ class PickServerCell: UITableViewCell { let usersTitleLabel: UILabel = { let label = UILabel() label.textColor = Asset.Colors.Label.primary.color - label.font = .preferredFont(forTextStyle: .caption2) + label.font = UIFontMetrics(forTextStyle: .subheadline).scaledFont(for: .systemFont(ofSize: 11, weight: .regular), maximumPointSize: 16) label.text = L10n.Scene.ServerPicker.Label.users label.textAlignment = .center label.adjustsFontForContentSizeCategory = true @@ -158,7 +158,7 @@ class PickServerCell: UITableViewCell { let categoryTitleLabel: UILabel = { let label = UILabel() label.textColor = Asset.Colors.Label.primary.color - label.font = .preferredFont(forTextStyle: .caption2) + label.font = UIFontMetrics(forTextStyle: .subheadline).scaledFont(for: .systemFont(ofSize: 11, weight: .regular), maximumPointSize: 16) label.text = L10n.Scene.ServerPicker.Label.category label.textAlignment = .center label.adjustsFontForContentSizeCategory = true diff --git a/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController.swift b/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController.swift index 007012d3..48401c0c 100644 --- a/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController.swift +++ b/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewController.swift @@ -63,6 +63,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency, O label.font = UIFontMetrics(forTextStyle: .largeTitle).scaledFont(for: UIFont.boldSystemFont(ofSize: 34)) label.textColor = Asset.Colors.Label.primary.color label.text = L10n.Scene.Register.title + label.numberOfLines = 0 return label }() @@ -99,7 +100,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency, O let domainLabel: UILabel = { let label = UILabel() - label.font = .preferredFont(forTextStyle: .headline) + label.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold), maximumPointSize: 22) label.textColor = Asset.Colors.Label.primary.color return label }() @@ -113,7 +114,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency, O textField.textColor = Asset.Colors.Label.primary.color textField.attributedPlaceholder = NSAttributedString(string: L10n.Scene.Register.Input.Username.placeholder, attributes: [NSAttributedString.Key.foregroundColor: Asset.Colors.Label.secondary.color, - NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .headline)]) + NSAttributedString.Key.font: UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold), maximumPointSize: 22)]) textField.borderStyle = UITextField.BorderStyle.roundedRect let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: 5, height: textField.frame.height)) textField.leftView = paddingView @@ -136,7 +137,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency, O textField.textColor = Asset.Colors.Label.primary.color textField.attributedPlaceholder = NSAttributedString(string: L10n.Scene.Register.Input.DisplayName.placeholder, attributes: [NSAttributedString.Key.foregroundColor: Asset.Colors.Label.secondary.color, - NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .headline)]) + NSAttributedString.Key.font: UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold), maximumPointSize: 22)]) textField.borderStyle = UITextField.BorderStyle.roundedRect let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: 5, height: textField.frame.height)) textField.leftView = paddingView @@ -153,7 +154,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency, O textField.textColor = Asset.Colors.Label.primary.color textField.attributedPlaceholder = NSAttributedString(string: L10n.Scene.Register.Input.Email.placeholder, attributes: [NSAttributedString.Key.foregroundColor: Asset.Colors.Label.secondary.color, - NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .headline)]) + NSAttributedString.Key.font: UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold), maximumPointSize: 22)]) textField.borderStyle = UITextField.BorderStyle.roundedRect let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: 5, height: textField.frame.height)) textField.leftView = paddingView @@ -178,7 +179,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency, O textField.textColor = Asset.Colors.Label.primary.color textField.attributedPlaceholder = NSAttributedString(string: L10n.Scene.Register.Input.Password.placeholder, attributes: [NSAttributedString.Key.foregroundColor: Asset.Colors.Label.secondary.color, - NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .headline)]) + NSAttributedString.Key.font: UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold), maximumPointSize: 22)]) textField.borderStyle = UITextField.BorderStyle.roundedRect let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: 5, height: textField.frame.height)) textField.leftView = paddingView @@ -208,7 +209,7 @@ final class MastodonRegisterViewController: UIViewController, NeedsDependency, O textField.textColor = Asset.Colors.Label.primary.color textField.attributedPlaceholder = NSAttributedString(string: L10n.Scene.Register.Input.Invite.registrationUserInviteRequest, attributes: [NSAttributedString.Key.foregroundColor: Asset.Colors.Label.secondary.color, - NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .headline)]) + NSAttributedString.Key.font: UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 17, weight: .semibold), maximumPointSize: 22)]) textField.borderStyle = UITextField.BorderStyle.roundedRect let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: 5, height: textField.frame.height)) textField.leftView = paddingView diff --git a/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewModel.swift b/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewModel.swift index 309204a9..85b934a2 100644 --- a/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewModel.swift +++ b/Mastodon/Scene/Onboarding/Register/MastodonRegisterViewModel.swift @@ -223,7 +223,7 @@ extension MastodonRegisterViewModel { } static func attributeStringForPassword(validateState: ValidateState) -> NSAttributedString { - let font = UIFont.preferredFont(forTextStyle: .caption1) + let font = UIFontMetrics(forTextStyle: .caption1).scaledFont(for: .systemFont(ofSize: 13, weight: .regular), maximumPointSize: 18) let attributeString = NSMutableAttributedString() let image = MastodonRegisterViewModel.checkmarkImage(font: font) @@ -236,7 +236,7 @@ extension MastodonRegisterViewModel { } static func errorPromptAttributedString(for prompt: String) -> NSAttributedString { - let font = UIFont.preferredFont(forTextStyle: .caption1) + let font = UIFontMetrics(forTextStyle: .caption1).scaledFont(for: .systemFont(ofSize: 13, weight: .regular), maximumPointSize: 18) let attributeString = NSMutableAttributedString() let image = MastodonRegisterViewModel.xmarkImage(font: font) diff --git a/Mastodon/Scene/Onboarding/ServerRules/MastodonServerRulesViewController.swift b/Mastodon/Scene/Onboarding/ServerRules/MastodonServerRulesViewController.swift index d8638421..d865c96e 100644 --- a/Mastodon/Scene/Onboarding/ServerRules/MastodonServerRulesViewController.swift +++ b/Mastodon/Scene/Onboarding/ServerRules/MastodonServerRulesViewController.swift @@ -25,6 +25,7 @@ final class MastodonServerRulesViewController: UIViewController, NeedsDependency label.font = UIFontMetrics(forTextStyle: .largeTitle).scaledFont(for: .systemFont(ofSize: 34, weight: .bold)) label.textColor = .label label.text = L10n.Scene.ServerRules.title + label.numberOfLines = 0 return label }() @@ -54,7 +55,7 @@ final class MastodonServerRulesViewController: UIViewController, NeedsDependency private(set) lazy var bottomPromptTextView: UITextView = { let textView = UITextView() - textView.font = .preferredFont(forTextStyle: .body) + textView.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 17, weight: .regular), maximumPointSize: 22) textView.textColor = .label textView.isSelectable = true textView.isEditable = false @@ -181,7 +182,7 @@ extension MastodonServerRulesViewController { let str = NSString(string: L10n.Scene.ServerRules.prompt(viewModel.domain)) let termsOfServiceRange = str.range(of: L10n.Scene.ServerRules.termsOfService) let privacyRange = str.range(of: L10n.Scene.ServerRules.privacyPolicy) - let attributeString = NSMutableAttributedString(string: L10n.Scene.ServerRules.prompt(viewModel.domain), attributes: [NSAttributedString.Key.font: UIFont.preferredFont(forTextStyle: .body), NSAttributedString.Key.foregroundColor: UIColor.label]) + let attributeString = NSMutableAttributedString(string: L10n.Scene.ServerRules.prompt(viewModel.domain), attributes: [NSAttributedString.Key.font: UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 17, weight: .regular), maximumPointSize: 22), NSAttributedString.Key.foregroundColor: UIColor.label]) attributeString.addAttribute(.link, value: Mastodon.API.serverRulesURL(domain: viewModel.domain), range: termsOfServiceRange) attributeString.addAttribute(.link, value: Mastodon.API.privacyURL(domain: viewModel.domain), range: privacyRange) let linkAttributes = [NSAttributedString.Key.foregroundColor:linkColor] diff --git a/Mastodon/Scene/Profile/Header/View/ProfileHeaderView.swift b/Mastodon/Scene/Profile/Header/View/ProfileHeaderView.swift index 0bcc68bf..e37427e3 100644 --- a/Mastodon/Scene/Profile/Header/View/ProfileHeaderView.swift +++ b/Mastodon/Scene/Profile/Header/View/ProfileHeaderView.swift @@ -100,7 +100,7 @@ final class ProfileHeaderView: UIView { let nameTextField: UITextField = { let textField = UITextField() - textField.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 20, weight: .semibold)) + textField.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: .systemFont(ofSize: 20, weight: .semibold), maximumPointSize: 28) textField.textColor = .white textField.text = "Alice" textField.autocorrectionType = .no @@ -111,7 +111,7 @@ final class ProfileHeaderView: UIView { let usernameLabel: UILabel = { let label = UILabel() - label.font = UIFontMetrics(forTextStyle: .subheadline).scaledFont(for: .systemFont(ofSize: 15, weight: .regular)) + label.font = UIFontMetrics(forTextStyle: .subheadline).scaledFont(for: .systemFont(ofSize: 15, weight: .regular), maximumPointSize: 20) label.adjustsFontSizeToFitWidth = true label.minimumScaleFactor = 0.5 label.textColor = Asset.Scene.Profile.Banner.usernameGray.color diff --git a/Mastodon/Scene/Settings/SettingsViewController.swift b/Mastodon/Scene/Settings/SettingsViewController.swift index 3c4a101a..39bafdf4 100644 --- a/Mastodon/Scene/Settings/SettingsViewController.swift +++ b/Mastodon/Scene/Settings/SettingsViewController.swift @@ -51,21 +51,27 @@ class SettingsViewController: UIViewController, NeedsDependency { return menu } - private(set) lazy var notifySectionHeader: UIView = { + private let notifySectionHeaderStackView: UIStackView = { let view = UIStackView() view.translatesAutoresizingMaskIntoConstraints = false view.isLayoutMarginsRelativeArrangement = true - //view.layoutMargins = UIEdgeInsets(top: 15, left: 4, bottom: 5, right: 4) view.axis = .horizontal view.alignment = .fill view.distribution = .equalSpacing view.spacing = 4 + return view + }() + + private(set) lazy var notifySectionHeader: UIView = { + let view = notifySectionHeaderStackView let notifyLabel = UILabel() notifyLabel.translatesAutoresizingMaskIntoConstraints = false - notifyLabel.font = UIFontMetrics(forTextStyle: .title3).scaledFont(for: UIFont.systemFont(ofSize: 20, weight: .semibold)) + notifyLabel.font = UIFontMetrics(forTextStyle: .headline).scaledFont(for: UIFont.systemFont(ofSize: 20, weight: .semibold)) notifyLabel.textColor = Asset.Colors.Label.primary.color notifyLabel.text = L10n.Scene.Settings.Section.Notifications.Trigger.title + // accessibility + notifyLabel.numberOfLines = 0 view.addArrangedSubview(notifyLabel) view.addArrangedSubview(whoButton) return view @@ -138,7 +144,22 @@ class SettingsViewController: UIViewController, NeedsDependency { } } + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + + updateSectionHeaderStackViewLayout() + } + + // MAKR: - Private methods + private func updateSectionHeaderStackViewLayout() { + if traitCollection.preferredContentSizeCategory < .accessibilityMedium { + notifySectionHeaderStackView.axis = .horizontal + } else { + notifySectionHeaderStackView.axis = .vertical + } + } + private func bindViewModel() { self.whoButton.setTitle(viewModel.setting.value.activeSubscription?.policy.title, for: .normal) viewModel.setting @@ -173,6 +194,8 @@ class SettingsViewController: UIViewController, NeedsDependency { tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor), ]) setupTableView() + + updateSectionHeaderStackViewLayout() } private func setupNavigation() { diff --git a/Mastodon/Scene/Share/View/Content/ContentWarningOverlayView.swift b/Mastodon/Scene/Share/View/Content/ContentWarningOverlayView.swift index f04a56e9..6cf62783 100644 --- a/Mastodon/Scene/Share/View/Content/ContentWarningOverlayView.swift +++ b/Mastodon/Scene/Share/View/Content/ContentWarningOverlayView.swift @@ -36,7 +36,7 @@ class ContentWarningOverlayView: UIView { }() let blurContentWarningTitleLabel: UILabel = { let label = UILabel() - label.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 17)) + label.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 17), maximumPointSize: 23) label.text = L10n.Common.Controls.Status.mediaContentWarning label.textColor = Asset.Colors.Label.primary.color label.textAlignment = .center @@ -44,7 +44,7 @@ class ContentWarningOverlayView: UIView { }() let blurContentWarningLabel: UILabel = { let label = UILabel() - label.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 15)) + label.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 15), maximumPointSize: 20) label.text = L10n.Common.Controls.Status.mediaContentWarning label.textColor = Asset.Colors.Label.secondary.color label.textAlignment = .center diff --git a/Mastodon/Scene/Share/View/Content/StatusView.swift b/Mastodon/Scene/Share/View/Content/StatusView.swift index 20437a8d..17937383 100644 --- a/Mastodon/Scene/Share/View/Content/StatusView.swift +++ b/Mastodon/Scene/Share/View/Content/StatusView.swift @@ -71,7 +71,7 @@ final class StatusView: UIView { let headerInfoLabel: UILabel = { let label = UILabel() - label.font = UIFontMetrics(forTextStyle: .footnote).scaledFont(for: .systemFont(ofSize: 13, weight: .medium)) + label.font = UIFontMetrics(forTextStyle: .footnote).scaledFont(for: .systemFont(ofSize: 13, weight: .medium), maximumPointSize: 17) label.textColor = Asset.Colors.Label.secondary.color label.text = "Bob reblogged" return label diff --git a/Mastodon/Scene/Share/View/Content/ThreadMetaView.swift b/Mastodon/Scene/Share/View/Content/ThreadMetaView.swift index 16d1b04a..e84939d3 100644 --- a/Mastodon/Scene/Share/View/Content/ThreadMetaView.swift +++ b/Mastodon/Scene/Share/View/Content/ThreadMetaView.swift @@ -34,6 +34,14 @@ final class ThreadMetaView: UIView { return button }() + let containerStackView: UIStackView = { + let stackView = UIStackView() + stackView.axis = .horizontal + stackView.spacing = 20 + return stackView + }() + let actionButtonStackView = UIStackView() + override init(frame: CGRect) { super.init(frame: frame) _init() @@ -48,27 +56,48 @@ final class ThreadMetaView: UIView { extension ThreadMetaView { private func _init() { - let stackView = UIStackView() - stackView.axis = .horizontal - stackView.spacing = 20 - stackView.translatesAutoresizingMaskIntoConstraints = false - addSubview(stackView) + containerStackView.translatesAutoresizingMaskIntoConstraints = false + addSubview(containerStackView) NSLayoutConstraint.activate([ - stackView.topAnchor.constraint(equalTo: topAnchor, constant: 8), - stackView.leadingAnchor.constraint(equalTo: leadingAnchor), - stackView.trailingAnchor.constraint(equalTo: trailingAnchor), - bottomAnchor.constraint(equalTo: stackView.bottomAnchor, constant: 12), + containerStackView.topAnchor.constraint(equalTo: topAnchor, constant: 8), + containerStackView.leadingAnchor.constraint(equalTo: leadingAnchor), + containerStackView.trailingAnchor.constraint(equalTo: trailingAnchor), + bottomAnchor.constraint(equalTo: containerStackView.bottomAnchor, constant: 12), ]) - stackView.addArrangedSubview(dateLabel) - stackView.addArrangedSubview(reblogButton) - stackView.addArrangedSubview(favoriteButton) + containerStackView.addArrangedSubview(dateLabel) + containerStackView.addArrangedSubview(actionButtonStackView) + + actionButtonStackView.axis = .horizontal + actionButtonStackView.addArrangedSubview(reblogButton) + actionButtonStackView.addArrangedSubview(favoriteButton) dateLabel.setContentHuggingPriority(.defaultLow, for: .horizontal) reblogButton.setContentHuggingPriority(.required - 2, for: .horizontal) favoriteButton.setContentHuggingPriority(.required - 1, for: .horizontal) + + updateContainerLayout() } + + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { + super.traitCollectionDidChange(previousTraitCollection) + + updateContainerLayout() + } + + private func updateContainerLayout() { + if traitCollection.preferredContentSizeCategory < .accessibilityMedium { + containerStackView.axis = .horizontal + containerStackView.spacing = 20 + dateLabel.numberOfLines = 1 + } else { + containerStackView.axis = .vertical + containerStackView.spacing = 4 + dateLabel.numberOfLines = 0 + } + } + } #if canImport(SwiftUI) && DEBUG