summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadVPN/Views/ScaledSegmentedControl.swift
diff options
context:
space:
mode:
authormojganii <mojgan.jelodar@mullvad.net>2025-07-01 13:46:30 +0200
committerMarkus Pettersson <markus.pettersson@mullvad.net>2025-07-17 14:05:24 +0200
commit6e92f0fe096048770e534d30ca04087d4bc714a4 (patch)
treec1ab9ce0daea35bfceff8b721f56032b30d99b37 /ios/MullvadVPN/Views/ScaledSegmentedControl.swift
parentae02a1f9b790d5d8966b55f918227a0983789035 (diff)
downloadmullvadvpn-6e92f0fe096048770e534d30ca04087d4bc714a4.tar.xz
mullvadvpn-6e92f0fe096048770e534d30ca04087d4bc714a4.zip
Fix dynamic sizing and layout issues across multiple views
- Fix font scaling and overlapping in device management - Adjust font size for account number - Scale info button dynamically - Resolve dynamic size issues in: - Settings - IP overrides - API access - Filter view and filter chips - Select location - Edit API access method - MullvadList - Fix line breaks in settings view - Unify padding across pages
Diffstat (limited to 'ios/MullvadVPN/Views/ScaledSegmentedControl.swift')
-rw-r--r--ios/MullvadVPN/Views/ScaledSegmentedControl.swift61
1 files changed, 61 insertions, 0 deletions
diff --git a/ios/MullvadVPN/Views/ScaledSegmentedControl.swift b/ios/MullvadVPN/Views/ScaledSegmentedControl.swift
new file mode 100644
index 0000000000..ab477a3be5
--- /dev/null
+++ b/ios/MullvadVPN/Views/ScaledSegmentedControl.swift
@@ -0,0 +1,61 @@
+//
+// ScaledSegmentedControl.swift
+// MullvadVPN
+//
+// Created by Mojgan on 2025-07-02.
+// Copyright © 2025 Mullvad VPN AB. All rights reserved.
+//
+import UIKit
+
+final class ScaledSegmentedControl: UISegmentedControl {
+ private let textStyle: UIFont.TextStyle
+ private let fontWeight: UIFont.Weight
+
+ init(textStyle: UIFont.TextStyle = .body, weight: UIFont.Weight = .regular) {
+ self.textStyle = textStyle
+ self.fontWeight = weight
+ super.init(frame: .zero)
+ applyTextAttributes()
+ subscribeToDynamicType()
+ }
+
+ required init?(coder: NSCoder) {
+ self.textStyle = .body
+ self.fontWeight = .regular
+ super.init(coder: coder)
+ applyTextAttributes()
+ subscribeToDynamicType()
+ }
+
+ override func insertSegment(withTitle title: String?, at segment: Int, animated: Bool) {
+ super.insertSegment(withTitle: title, at: segment, animated: animated)
+ applyTextAttributes()
+ }
+
+ private func applyTextAttributes() {
+ let font = UIFont.preferredFont(forTextStyle: textStyle).withWeight(fontWeight)
+ let attributes: [NSAttributedString.Key: Any] = [
+ .font: font,
+ .foregroundColor: UIColor.primaryTextColor,
+ ]
+ setTitleTextAttributes(attributes, for: .normal)
+ setTitleTextAttributes(attributes, for: .selected)
+ }
+
+ private func subscribeToDynamicType() {
+ NotificationCenter.default.addObserver(
+ self,
+ selector: #selector(contentSizeChanged),
+ name: UIContentSizeCategory.didChangeNotification,
+ object: nil
+ )
+ }
+
+ @objc private func contentSizeChanged() {
+ applyTextAttributes()
+ }
+
+ deinit {
+ NotificationCenter.default.removeObserver(self)
+ }
+}