Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix button placement when using large font #461

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions MoppApp/MoppApp/IdCardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class IdCardViewController : MoppViewController, TokenFlowSigning {
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var pinCodeStackView: UIStackView!
@IBOutlet weak var pinTextField: UITextField!
@IBOutlet weak var cancelButton: UIButton!
@IBOutlet weak var actionButton: UIButton!
@IBOutlet weak var cancelButton: ScaledButton!
@IBOutlet weak var actionButton: ScaledButton!
@IBOutlet weak var pinTextFieldTitleLabel: UILabel!
@IBOutlet weak var loadingSpinner: SpinnerView!

Expand Down Expand Up @@ -95,6 +95,9 @@ class IdCardViewController : MoppViewController, TokenFlowSigning {
actionButton.setTitle(L(.actionSign).uppercased())
actionButton.accessibilityLabel = L(.actionSign).lowercased()
}

cancelButton.adjustedFont()
actionButton.adjustedFont()

pinTextField.delegate = self
pinTextField.addTarget(self, action: #selector(editingChanged(sender:)), for: .editingChanged)
Expand Down
3 changes: 3 additions & 0 deletions MoppApp/MoppApp/MobileIDEditViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class MobileIDEditViewController : MoppViewController, TokenFlowSigning {
signButton.setTitle(L(.actionSign).uppercased())
rememberLabel.text = L(.signingRememberMe)

cancelButton.adjustedFont()
signButton.adjustedFont()

rememberLabel.isAccessibilityElement = false
rememberSwitch.accessibilityLabel = L(.signingRememberMe)

Expand Down
15 changes: 15 additions & 0 deletions MoppApp/MoppApp/ScaledButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import Foundation

class ScaledButton: UIButton {

private static let defaultMaxFontSize = CGFloat(20)

override init(frame: CGRect) {
super.init(frame: frame)
scaleButton()
Expand Down Expand Up @@ -72,4 +74,17 @@ class ScaledButton: UIButton {
func mediumFont() {
self.titleLabel?.font = FontUtil.mediumFont(font: UIFont(name: "Roboto-Medium", size: 17) ?? UIFont())
}

func adjustedFont(_ maxFontSize: CGFloat = CGFloat(defaultMaxFontSize)) {
if let buttonLabel = self.titleLabel {
let originalFont = buttonLabel.font
let scaledPointSize = UIFontMetrics.default.scaledValue(for: originalFont?.pointSize ?? CGFloat(maxFontSize))
let maxPointSize = min(maxFontSize, scaledPointSize)
let adjustedFont = originalFont?.withSize(maxPointSize)
buttonLabel.font = adjustedFont

self.titleLabel?.sizeToFit()
self.sizeToFit()
}
}
}
7 changes: 5 additions & 2 deletions MoppApp/MoppApp/SmartIDEditViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class SmartIDEditViewController : MoppViewController, TokenFlowSigning {
@IBOutlet weak var countryLabel: UILabel!
@IBOutlet weak var idCodeLabel: UILabel!
@IBOutlet weak var personalCodeErrorLabel: UILabel!
@IBOutlet weak var cancelButton: UIButton!
@IBOutlet weak var signButton: UIButton!
@IBOutlet weak var cancelButton: ScaledButton!
@IBOutlet weak var signButton: ScaledButton!
@IBOutlet weak var rememberLabel: UILabel!
@IBOutlet weak var rememberSwitch: UISwitch!
@IBOutlet weak var rememberStackView: UIStackView!
Expand All @@ -80,6 +80,9 @@ class SmartIDEditViewController : MoppViewController, TokenFlowSigning {
cancelButton.setTitle(L(.actionCancel).uppercased())
signButton.setTitle(L(.actionSign).uppercased())
rememberLabel.text = L(.signingRememberMe)

cancelButton.adjustedFont()
signButton.adjustedFont()

rememberLabel.isAccessibilityElement = false
rememberSwitch.accessibilityLabel = L(.signingRememberMe)
Expand Down
9 changes: 6 additions & 3 deletions MoppApp/MoppApp/TokenFlowSelectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class TokenFlowSelectionViewController : MoppViewController {
@IBOutlet weak var containerView: UIView!
@IBOutlet weak var tokenNavbarView: UIView!
@IBOutlet weak var tokenNavbar: UIView!
@IBOutlet weak var mobileIDButton: UIButton!
@IBOutlet weak var smartIDButton: UIButton!
@IBOutlet weak var idCardButton: UIButton!
@IBOutlet weak var mobileIDButton: ScaledButton!
@IBOutlet weak var smartIDButton: ScaledButton!
@IBOutlet weak var idCardButton: ScaledButton!

@IBOutlet weak var tokenViewContainerTopConstraint: NSLayoutConstraint!
@IBOutlet weak var tokenFlowViewLeadingCSTR: NSLayoutConstraint!
Expand Down Expand Up @@ -129,14 +129,17 @@ class TokenFlowSelectionViewController : MoppViewController {
$0.setTitle(L(.signTitleIdCard))
idCardButton.accessibilityLabel = setTabAccessibilityLabel(isTabSelected: false, tabName: L(.signTitleIdCard), positionInRow: "3", viewCount: "3")
idCardButton.accessibilityUserInputLabels = [L(.voiceControlIdCard)]
idCardButton.adjustedFont()
case .mobileID:
$0.setTitle(L(.signTitleMobileId))
mobileIDButton.accessibilityLabel = setTabAccessibilityLabel(isTabSelected: false, tabName: L(.signTitleMobileId), positionInRow: "1", viewCount: "3")
mobileIDButton.accessibilityUserInputLabels = [L(.voiceControlMobileId)]
mobileIDButton.adjustedFont()
case .smartID:
$0.setTitle(L(.signTitleSmartId))
smartIDButton.accessibilityLabel = setTabAccessibilityLabel(isTabSelected: false, tabName: L(.signTitleSmartId), positionInRow: "2", viewCount: "3")
smartIDButton.accessibilityUserInputLabels = [L(.voiceControlSmartId)]
smartIDButton.adjustedFont()
}
}
}
Expand Down