From 7806816213b5250fa7c4910860987b3ea01d055d Mon Sep 17 00:00:00 2001 From: CMK Date: Wed, 4 Aug 2021 16:24:19 +0800 Subject: [PATCH] fix: some label trimmed under zoomed display mode issue --- .../Section/Status/NotificationSection.swift | 6 ++-- Mastodon/Extension/UIView.swift | 6 ++++ .../NotificationStatusTableViewCell.swift | 28 +++++++++++++++++-- .../ProfileStatusDashboardMeterView.swift | 4 +++ .../View/ProfileStatusDashboardView.swift | 2 +- .../SearchRecommendCollectionHeader.swift | 2 ++ .../Cell/SettingsToggleTableViewCell.swift | 1 + 7 files changed, 43 insertions(+), 6 deletions(-) diff --git a/Mastodon/Diffiable/Section/Status/NotificationSection.swift b/Mastodon/Diffiable/Section/Status/NotificationSection.swift index 3113a446..b0afd700 100644 --- a/Mastodon/Diffiable/Section/Status/NotificationSection.swift +++ b/Mastodon/Diffiable/Section/Status/NotificationSection.swift @@ -78,12 +78,14 @@ extension NotificationSection { } let createAt = notification.createAt let actionText = notification.notificationType.actionText - cell.actionLabel.text = actionText + " · " + createAt.timeAgoSinceNow + cell.actionLabel.text = actionText + cell.timestampLabel.text = createAt.timeAgoSinceNow AppContext.shared.timestampUpdatePublisher .receive(on: DispatchQueue.main) .sink { [weak cell] _ in guard let cell = cell else { return } - cell.actionLabel.text = actionText + " · " + createAt.timeAgoSinceNow + cell.actionLabel.text = actionText + cell.timestampLabel.text = createAt.timeAgoSinceNow } .store(in: &cell.disposeBag) diff --git a/Mastodon/Extension/UIView.swift b/Mastodon/Extension/UIView.swift index 85d8112c..0f43dced 100644 --- a/Mastodon/Extension/UIView.swift +++ b/Mastodon/Extension/UIView.swift @@ -67,3 +67,9 @@ extension UIView { return self } } + +extension UIView { + static var isZoomedMode: Bool { + return UIScreen.main.scale != UIScreen.main.nativeScale + } +} diff --git a/Mastodon/Scene/Notification/TableViewCell/NotificationStatusTableViewCell.swift b/Mastodon/Scene/Notification/TableViewCell/NotificationStatusTableViewCell.swift index 65e4dbcd..804fc081 100644 --- a/Mastodon/Scene/Notification/TableViewCell/NotificationStatusTableViewCell.swift +++ b/Mastodon/Scene/Notification/TableViewCell/NotificationStatusTableViewCell.swift @@ -56,6 +56,19 @@ final class NotificationStatusTableViewCell: UITableViewCell, StatusCell { label.lineBreakMode = .byTruncatingTail return label }() + let dotLabel: UILabel = { + let label = UILabel() + label.textColor = Asset.Colors.Label.secondary.color + label.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 15, weight: .regular), maximumPointSize: 20) + label.text = "·" + return label + }() + let timestampLabel: UILabel = { + let label = UILabel() + label.textColor = Asset.Colors.Label.secondary.color + label.font = UIFontMetrics(forTextStyle: .body).scaledFont(for: .systemFont(ofSize: 15, weight: .regular), maximumPointSize: 20) + return label + }() let nameLabel = MetaLabel(style: .notificationName) @@ -170,12 +183,21 @@ extension NotificationStatusTableViewCell { actionStackView.addArrangedSubview(nameLabel) actionStackView.addArrangedSubview(actionLabel) - nameLabel.setContentHuggingPriority(.required - 1, for: .horizontal) + actionStackView.addArrangedSubview(dotLabel) + actionStackView.addArrangedSubview(timestampLabel) + let timestampPaddingView = UIView() + actionStackView.addArrangedSubview(timestampPaddingView) + nameLabel.setContentHuggingPriority(.required - 3, for: .horizontal) nameLabel.setContentHuggingPriority(.required - 1, for: .vertical) - nameLabel.setContentCompressionResistancePriority(.required - 1, for: .horizontal) + nameLabel.setContentCompressionResistancePriority(.required - 3, for: .horizontal) nameLabel.setContentCompressionResistancePriority(.required - 1, for: .vertical) actionLabel.setContentHuggingPriority(.defaultLow, for: .horizontal) - + dotLabel.setContentHuggingPriority(.required - 2, for: .horizontal) + dotLabel.setContentCompressionResistancePriority(.required - 2, for: .horizontal) + timestampLabel.setContentHuggingPriority(.required - 1, for: .horizontal) + timestampLabel.setContentCompressionResistancePriority(.required - 1, for: .horizontal) + timestampPaddingView.setContentHuggingPriority(.defaultLow, for: .horizontal) + // follow request contentStackView.addArrangedSubview(buttonStackView) buttonStackView.addArrangedSubview(acceptButton) diff --git a/Mastodon/Scene/Profile/Header/View/ProfileStatusDashboardMeterView.swift b/Mastodon/Scene/Profile/Header/View/ProfileStatusDashboardMeterView.swift index 4355fdc3..0f32f330 100644 --- a/Mastodon/Scene/Profile/Header/View/ProfileStatusDashboardMeterView.swift +++ b/Mastodon/Scene/Profile/Header/View/ProfileStatusDashboardMeterView.swift @@ -29,6 +29,10 @@ final class ProfileStatusDashboardMeterView: UIView { label.textColor = Asset.Colors.Label.primary.color label.text = L10n.Scene.Profile.Dashboard.posts label.textAlignment = .center + if UIView.isZoomedMode { + label.adjustsFontSizeToFitWidth = true + label.minimumScaleFactor = 0.8 + } return label }() diff --git a/Mastodon/Scene/Profile/Header/View/ProfileStatusDashboardView.swift b/Mastodon/Scene/Profile/Header/View/ProfileStatusDashboardView.swift index 38c093d1..0360421a 100644 --- a/Mastodon/Scene/Profile/Header/View/ProfileStatusDashboardView.swift +++ b/Mastodon/Scene/Profile/Header/View/ProfileStatusDashboardView.swift @@ -47,7 +47,7 @@ extension ProfileStatusDashboardView { containerStackView.heightAnchor.constraint(equalToConstant: 44).priority(.defaultHigh), ]) - let spacing: CGFloat = 16 + let spacing: CGFloat = UIView.isZoomedMode ? 4 : 16 containerStackView.spacing = spacing containerStackView.axis = .horizontal containerStackView.distribution = .fillEqually diff --git a/Mastodon/Scene/Search/Search/View/SearchRecommendCollectionHeader.swift b/Mastodon/Scene/Search/Search/View/SearchRecommendCollectionHeader.swift index 3db8c280..6c67580f 100644 --- a/Mastodon/Scene/Search/Search/View/SearchRecommendCollectionHeader.swift +++ b/Mastodon/Scene/Search/Search/View/SearchRecommendCollectionHeader.swift @@ -29,6 +29,8 @@ class SearchRecommendCollectionHeader: UIView { let button = HighlightDimmableButton(type: .custom) button.setTitleColor(Asset.Colors.brandBlue.color, for: .normal) button.setTitle(L10n.Scene.Search.Recommend.buttonText, for: .normal) + button.titleLabel?.adjustsFontSizeToFitWidth = true + button.titleLabel?.minimumScaleFactor = 0.8 return button }() diff --git a/Mastodon/Scene/Settings/View/Cell/SettingsToggleTableViewCell.swift b/Mastodon/Scene/Settings/View/Cell/SettingsToggleTableViewCell.swift index 2bc70e65..18c9e515 100644 --- a/Mastodon/Scene/Settings/View/Cell/SettingsToggleTableViewCell.swift +++ b/Mastodon/Scene/Settings/View/Cell/SettingsToggleTableViewCell.swift @@ -44,6 +44,7 @@ class SettingsToggleTableViewCell: UITableViewCell { private func setupUI() { selectionStyle = .none accessoryView = switchButton + textLabel?.numberOfLines = 0 switchButton.addTarget(self, action: #selector(switchValueDidChange(sender:)), for: .valueChanged) }