Skip to content

Commit 8a0b40c

Browse files
committed
APP字体大小跟随系统设置
1 parent efae838 commit 8a0b40c

14 files changed

+78
-35
lines changed

Bark.xcodeproj/project.pbxproj

+8
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@
9999
067B2EB525693E38008B6BE1 /* MessageTableViewCellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 067B2EB425693E38008B6BE1 /* MessageTableViewCellViewModel.swift */; };
100100
06802E5320ECC40C00767047 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0661A549204FDA4100965E4E /* Assets.xcassets */; };
101101
06840DBB272298FB001B3193 /* BKColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06840DBA272298FB001B3193 /* BKColor.swift */; };
102+
0687F2A82CCB791A00B2A52F /* UIFont+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0687F2A72CCB791A00B2A52F /* UIFont+Extension.swift */; };
103+
0687F2A92CCB791A00B2A52F /* UIFont+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0687F2A72CCB791A00B2A52F /* UIFont+Extension.swift */; };
104+
0687F2AA2CCB7FA500B2A52F /* UIFont+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0687F2A72CCB791A00B2A52F /* UIFont+Extension.swift */; };
102105
06885EB6247FB9880004A303 /* MessageSettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06885EB5247FB9880004A303 /* MessageSettingsViewController.swift */; };
103106
0689CF4C2C7484A7007203A6 /* BarkTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0689CF4B2C7484A7007203A6 /* BarkTabBarController.swift */; };
104107
068EC15827ED99C900D5D11E /* ServerListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 068EC15727ED99C900D5D11E /* ServerListViewController.swift */; };
@@ -326,6 +329,7 @@
326329
0683487020510FB20024B6DA /* UserNotifications.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserNotifications.framework; path = System/Library/Frameworks/UserNotifications.framework; sourceTree = SDKROOT; };
327330
0683487220510FB20024B6DA /* UserNotificationsUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UserNotificationsUI.framework; path = System/Library/Frameworks/UserNotificationsUI.framework; sourceTree = SDKROOT; };
328331
06840DBA272298FB001B3193 /* BKColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BKColor.swift; sourceTree = "<group>"; };
332+
0687F2A72CCB791A00B2A52F /* UIFont+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIFont+Extension.swift"; sourceTree = "<group>"; };
329333
06885EB5247FB9880004A303 /* MessageSettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageSettingsViewController.swift; sourceTree = "<group>"; };
330334
0689CF4B2C7484A7007203A6 /* BarkTabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BarkTabBarController.swift; sourceTree = "<group>"; };
331335
068EC15727ED99C900D5D11E /* ServerListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ServerListViewController.swift; sourceTree = "<group>"; };
@@ -582,6 +586,7 @@
582586
06F08EA629B1DDFE006AB9CA /* Error+Extension.swift */,
583587
06F08EAB29B1DECD006AB9CA /* NSLocalizedString+Extension.swift */,
584588
06E944742C07012E00AC86AB /* RealmConfiguration.swift */,
589+
0687F2A72CCB791A00B2A52F /* UIFont+Extension.swift */,
585590
);
586591
path = Common;
587592
sourceTree = "<group>";
@@ -1103,6 +1108,7 @@
11031108
isa = PBXSourcesBuildPhase;
11041109
buildActionMask = 2147483647;
11051110
files = (
1111+
0687F2AA2CCB7FA500B2A52F /* UIFont+Extension.swift in Sources */,
11061112
0632CE2320EC9098003FDF46 /* NotificationViewController.swift in Sources */,
11071113
);
11081114
runOnlyForDeploymentPostprocessing = 0;
@@ -1138,6 +1144,7 @@
11381144
066E0C8C2BB6AC9A00873838 /* AddSoundCell.swift in Sources */,
11391145
065BE4502563D939002A8CA4 /* SoundCellViewModel.swift in Sources */,
11401146
06F08EA729B1DDFE006AB9CA /* Error+Extension.swift in Sources */,
1147+
0687F2A82CCB791A00B2A52F /* UIFont+Extension.swift in Sources */,
11411148
06B1158F247BB1FB006D91FB /* Message.swift in Sources */,
11421149
06172FDA27F6DAEF002333A4 /* ServerListTableViewCell.swift in Sources */,
11431150
0653677829B727A60038BDB8 /* CryptoSettingRelay.swift in Sources */,
@@ -1218,6 +1225,7 @@
12181225
06E9447C2C07052F00AC86AB /* ImageProcessor.swift in Sources */,
12191226
06E9446A2C06E4A200AC86AB /* CiphertextProcessor.swift in Sources */,
12201227
06E944712C06FF4C00AC86AB /* AutoCopyProcessor.swift in Sources */,
1228+
0687F2A92CCB791A00B2A52F /* UIFont+Extension.swift in Sources */,
12211229
06F08EA829B1DE0A006AB9CA /* Error+Extension.swift in Sources */,
12221230
);
12231231
runOnlyForDeploymentPostprocessing = 0;

Common/UIFont+Extension.swift

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// UIFont+Extension.swift
3+
// Bark
4+
//
5+
// Created by huangfeng on 10/25/24.
6+
// Copyright © 2024 Fin. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
extension UIFont {
12+
class func preferredFont(ofSize size: CGFloat, weight: Weight = .regular) -> UIFont {
13+
return UIFontMetrics.default.scaledFont(for: UIFont.systemFont(ofSize: size, weight: weight))
14+
}
15+
}

Controller/CrashReportViewController.swift

+6-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class CrashReportViewController: UIViewController {
2020

2121
let crashedTitle = UILabel()
2222
crashedTitle.text = NSLocalizedString("crashed")
23-
crashedTitle.font = UIFont.boldSystemFont(ofSize: 30)
23+
crashedTitle.font = UIFont.preferredFont(ofSize: 30, weight: .bold)
24+
crashedTitle.adjustsFontForContentSizeCategory = true
2425
crashedTitle.textColor = UIColor(r255: 239, g255: 77, b255: 77)
2526
self.view.addSubview(crashedTitle)
2627

@@ -31,13 +32,15 @@ class CrashReportViewController: UIViewController {
3132
contentlabel.isScrollEnabled = false
3233
contentlabel.textContainerInset = .zero
3334
contentlabel.textContainer.lineFragmentPadding = 0
34-
contentlabel.font = UIFont.systemFont(ofSize: 14)
35+
contentlabel.font = UIFont.preferredFont(ofSize: 14)
36+
contentlabel.adjustsFontForContentSizeCategory = true
3537
contentlabel.textColor = UIColor(r255: 51, g255: 51, b255: 51)
3638
contentlabel.text = NSLocalizedString("crashContent")
3739
self.view.addSubview(contentlabel)
3840

3941
let copyButton = UIButton()
40-
copyButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 16)
42+
copyButton.titleLabel?.font = UIFont.preferredFont(ofSize: 16, weight: .bold)
43+
copyButton.titleLabel?.adjustsFontForContentSizeCategory = true
4144
copyButton.setTitleColor(UIColor.white, for: .normal)
4245
copyButton.setTitle(NSLocalizedString("copyCrashLog"), for: .normal)
4346
copyButton.backgroundColor = UIColor(r255: 239, g255: 77, b255: 77)

Controller/CryptoSettingController.swift

+8-4
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ class CryptoSettingController: BaseViewController<CryptoSettingViewModel> {
1616

1717
let keyTextField: BorderTextField = {
1818
let textField = BorderTextField(title: "Key")
19-
textField.font = UIFont.systemFont(ofSize: 14)
19+
textField.font = UIFont.preferredFont(ofSize: 14)
20+
textField.adjustsFontForContentSizeCategory = true
2021
textField.placeholder = String(format: NSLocalizedString("enterKey"), 16)
2122
return textField
2223
}()
2324

2425
let ivTextField: BorderTextField = {
2526
let textField = BorderTextField(title: "IV")
26-
textField.font = UIFont.systemFont(ofSize: 14)
27+
textField.font = UIFont.preferredFont(ofSize: 14)
28+
textField.adjustsFontForContentSizeCategory = true
2729
textField.placeholder = String(format: NSLocalizedString("enterIv"), 16) // todo: update iv length
2830
return textField
2931
}()
@@ -41,7 +43,8 @@ class CryptoSettingController: BaseViewController<CryptoSettingViewModel> {
4143
let btn = GradientButton()
4244
btn.setTitle(NSLocalizedString("copyExample"), for: .normal)
4345
btn.setTitleColor(UIColor.white, for: .normal)
44-
btn.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: .medium)
46+
btn.titleLabel?.font = UIFont.preferredFont(ofSize: 14, weight: .medium)
47+
btn.titleLabel?.adjustsFontForContentSizeCategory = true
4548
btn.layer.cornerRadius = 8
4649
btn.clipsToBounds = true
4750
btn.applyGradient(
@@ -70,7 +73,8 @@ class CryptoSettingController: BaseViewController<CryptoSettingViewModel> {
7073

7174
func getTitleLabel(title: String) -> UILabel {
7275
let label = UILabel()
73-
label.font = UIFont.systemFont(ofSize: 14)
76+
label.font = UIFont.preferredFont(ofSize: 14)
77+
label.adjustsFontForContentSizeCategory = true
7478
label.textColor = BKColor.grey.darken4
7579
label.text = title
7680
return label

Controller/NewServerViewController.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class NewServerViewController: BaseViewController<NewServerViewModel> {
4343
let label = UILabel()
4444
label.text = NSLocalizedString("DeploymentDocuments")
4545
label.textColor = BKColor.blue.base
46-
label.font = UIFont.systemFont(ofSize: 12)
46+
label.font = UIFont.preferredFont(ofSize: 12)
47+
label.adjustsFontForContentSizeCategory = true
4748
label.transition([.scale(0.85), .opacity(0), .translate(x: 50)])
4849
label.isUserInteractionEnabled = true
4950
label.addGestureRecognizer(UITapGestureRecognizer())

Controller/SoundsViewController.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,12 @@ extension SoundsViewController: UITableViewDelegate {
137137
string: fullText,
138138
attributes: [
139139
NSAttributedString.Key.foregroundColor: BKColor.grey.darken3,
140-
NSAttributedString.Key.font: RobotoFont.regular(with: 14)
140+
NSAttributedString.Key.font: UIFont.preferredFont(ofSize: 14)
141141
]
142142
)
143143
attrStr.setAttributes([
144144
NSAttributedString.Key.foregroundColor: BKColor.lightBlue.darken3,
145-
NSAttributedString.Key.font: RobotoFont.regular(with: 14)
145+
NSAttributedString.Key.font: UIFont.preferredFont(ofSize: 14)
146146
], range: (fullText as NSString).range(of: highlightText))
147147

148148
let label = UILabel()

View/AddSoundCell.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ class AddSoundCell: UITableViewCell {
1515
button.setImage(UIImage(named: "music_note-music_note_symbol"), for: .normal)
1616
button.setTitleColor(BKColor.lightBlue.darken3, for: .normal)
1717
button.tintColor = BKColor.lightBlue.darken3
18-
button.titleLabel?.font = UIFont.systemFont(ofSize: 16)
18+
button.titleLabel?.font = UIFont.preferredFont(ofSize: 16)
19+
button.titleLabel?.adjustsFontForContentSizeCategory = true
1920
// 从 UITableView didSelectRowAt 那响应点击事件
2021
button.isUserInteractionEnabled = false
2122
return button

View/BorderTextField.swift

+3-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ class BorderTextField: InsetTextField {
6565
self.insets = UIEdgeInsets(top: 0, left: 16, bottom: 0, right: 16)
6666

6767
self.textColor = BKColor.grey.darken3
68-
self.font = UIFont.systemFont(ofSize: 14)
68+
self.font = UIFont.preferredFont(ofSize: 14)
69+
self.adjustsFontForContentSizeCategory = true
6970
self.textAlignment = .left
7071

7172
self.insertSubview(backgroundView, at: 0)
@@ -78,7 +79,7 @@ class BorderTextField: InsetTextField {
7879
override var placeholder: String? {
7980
didSet{
8081
self.attributedPlaceholder = NSAttributedString(string: placeholder ?? "" , attributes: [
81-
.font: self.font ?? UIFont.systemFont(ofSize: 14),
82+
.font: self.font ?? UIFont.preferredFont(ofSize: 14),
8283
.foregroundColor: BKColor.grey.darken1
8384
])
8485
}

View/DropBoxView.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ class DropBoxView: UIView {
1515

1616
let valueLabel: UILabel = {
1717
let label = UILabel()
18-
label.font = UIFont.systemFont(ofSize: 14)
18+
label.font = UIFont.preferredFont(ofSize: 14)
19+
label.adjustsFontForContentSizeCategory = true
1920
label.textColor = BKColor.grey.darken3
2021
return label
2122
}()

View/MessageTableViewCell.swift

+9-7
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,17 @@ class MessageTableViewCell: BaseTableViewCell<MessageTableViewCellViewModel> {
2727
label.isScrollEnabled = false
2828
label.textContainerInset = .zero
2929
label.textContainer.lineFragmentPadding = 0
30-
label.font = RobotoFont.regular(with: 14)
30+
label.font = UIFont.preferredFont(ofSize: 14)
31+
label.adjustsFontForContentSizeCategory = true
3132
label.textColor = BKColor.grey.darken4
3233
return label
3334
}()
3435

3536
let dateLabel: UILabel = {
3637
let label = BKLabel()
3738
label.hitTestSlop = UIEdgeInsets(top: -5, left: -5, bottom: -5, right: -5)
38-
label.font = RobotoFont.medium(with: 11)
39+
label.font = UIFont.preferredFont(ofSize: 11, weight: .medium)
40+
label.adjustsFontForContentSizeCategory = true
3941
label.textColor = BKColor.grey.base
4042
label.isUserInteractionEnabled = true
4143
label.addGestureRecognizer(UITapGestureRecognizer())
@@ -97,31 +99,31 @@ class MessageTableViewCell: BaseTableViewCell<MessageTableViewCellViewModel> {
9799

98100
let text = NSMutableAttributedString(
99101
string: body,
100-
attributes: [.font: RobotoFont.regular(with: 14), .foregroundColor: BKColor.grey.darken4]
102+
attributes: [.font: UIFont.preferredFont(ofSize: 14), .foregroundColor: BKColor.grey.darken4]
101103
)
102104

103105
if title.count > 0 {
104106
// 插入一行空行当 spacer
105107
text.insert(NSAttributedString(
106108
string: "\n",
107-
attributes: [.font: RobotoFont.medium(with: 6)]
109+
attributes: [.font: UIFont.systemFont(ofSize: 6, weight: .medium)]
108110
), at: 0)
109111

110112
text.insert(NSAttributedString(
111113
string: title + "\n",
112-
attributes: [.font: RobotoFont.medium(with: 16), .foregroundColor: BKColor.grey.darken4]
114+
attributes: [.font: UIFont.preferredFont(ofSize: 16, weight: .medium), .foregroundColor: BKColor.grey.darken4]
113115
), at: 0)
114116
}
115117

116118
if url.count > 0 {
117119
// 插入一行空行当 spacer
118120
text.append(NSAttributedString(
119121
string: "\n ",
120-
attributes: [.font: RobotoFont.medium(with: 8)]
122+
attributes: [.font: UIFont.systemFont(ofSize: 8, weight: .medium)]
121123
))
122124

123125
text.append(NSAttributedString(string: "\n\(url)", attributes: [
124-
.font: RobotoFont.regular(with: 14),
126+
.font: UIFont.preferredFont(ofSize: 14),
125127
.foregroundColor: BKColor.grey.darken4,
126128
.link: url
127129
]))

View/PreviewCardCell.swift

+8-4
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,26 @@ class PreviewCardCell: BaseTableViewCell<PreviewCardCellViewModel> {
1515

1616
let titleLabel: UILabel = {
1717
let label = UILabel()
18-
label.font = RobotoFont.regular(with: 14)
18+
label.font = UIFont.preferredFont(ofSize: 14)
19+
label.adjustsFontForContentSizeCategory = true
1920
label.textColor = BKColor.grey.darken3
2021
label.numberOfLines = 0
2122
return label
2223
}()
2324

2425
let bodyLabel: UILabel = {
2526
let label = UILabel()
26-
label.font = RobotoFont.regular(with: 14)
27+
label.font = UIFont.preferredFont(ofSize: 14)
28+
label.adjustsFontForContentSizeCategory = true
2729
label.textColor = BKColor.grey.darken2
2830
label.numberOfLines = 0
2931
return label
3032
}()
3133

3234
let noticeLabel: UILabel = {
3335
let label = UILabel()
34-
label.font = RobotoFont.regular(with: 12)
36+
label.font = UIFont.preferredFont(ofSize: 12)
37+
label.adjustsFontForContentSizeCategory = true
3538
label.textColor = BKColor.grey.base
3639
label.numberOfLines = 0
3740
label.isUserInteractionEnabled = true
@@ -58,7 +61,8 @@ class PreviewCardCell: BaseTableViewCell<PreviewCardCellViewModel> {
5861
let label = UILabel()
5962
label.lineBreakMode = .byCharWrapping
6063
label.numberOfLines = 0
61-
label.font = RobotoFont.regular(with: 14)
64+
label.font = UIFont.preferredFont(ofSize: 14)
65+
label.adjustsFontForContentSizeCategory = true
6266
return label
6367
}()
6468

View/PreviewCardCellViewModel.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ class PreviewCardCellViewModel: ViewModel {
4848
let noticeStr = "\(previewModel.notice ?? "")"
4949
let noticeAttrStr = NSMutableAttributedString(string: noticeStr, attributes: [
5050
NSAttributedString.Key.foregroundColor: BKColor.grey.base,
51-
NSAttributedString.Key.font: RobotoFont.regular(with: 12)
51+
NSAttributedString.Key.font: UIFont.preferredFont(ofSize: 12)
5252
])
5353

5454
if let moreInfo = previewModel.moreInfo {
5555
noticeAttrStr.append(NSMutableAttributedString(string: " \(moreInfo)", attributes: [
5656
NSAttributedString.Key.foregroundColor: BKColor.blue.base,
57-
NSAttributedString.Key.font: RobotoFont.regular(with: 12)
57+
NSAttributedString.Key.font: UIFont.preferredFont(ofSize: 12)
5858
]))
5959
}
6060
notice.accept(noticeAttrStr)
@@ -69,30 +69,30 @@ class PreviewCardCellViewModel: ViewModel {
6969
let attrStr = NSMutableAttributedString(string: "")
7070
attrStr.append(NSAttributedString(string: serverUrl.absoluteString, attributes: [
7171
NSAttributedString.Key.foregroundColor: BKColor.grey.darken4,
72-
NSAttributedString.Key.font: RobotoFont.regular(with: fontSize)
72+
NSAttributedString.Key.font: UIFont.preferredFont(ofSize: fontSize)
7373
]))
7474
let key = ServerManager.shared.currentServer.key
7575
attrStr.append(NSAttributedString(string: "/\(key.count > 0 ? key : "Your Key")", attributes: [
7676
NSAttributedString.Key.foregroundColor: BKColor.grey.darken3,
77-
NSAttributedString.Key.font: RobotoFont.regular(with: fontSize)
77+
NSAttributedString.Key.font: UIFont.preferredFont(ofSize: fontSize)
7878
]))
7979

8080
if let modelTitle = previewModel.title {
8181
attrStr.append(NSAttributedString(string: "/\(modelTitle)", attributes: [
8282
NSAttributedString.Key.foregroundColor: BKColor.grey.darken1,
83-
NSAttributedString.Key.font: RobotoFont.regular(with: fontSize)
83+
NSAttributedString.Key.font: UIFont.preferredFont(ofSize: fontSize)
8484
]))
8585
}
8686
if let modelBody = previewModel.body {
8787
attrStr.append(NSAttributedString(string: "/\(modelBody)", attributes: [
8888
NSAttributedString.Key.foregroundColor: BKColor.grey.base,
89-
NSAttributedString.Key.font: RobotoFont.regular(with: fontSize)
89+
NSAttributedString.Key.font: UIFont.preferredFont(ofSize: fontSize)
9090
]))
9191
}
9292
if let queryParameter = previewModel.queryParameter {
9393
attrStr.append(NSAttributedString(string: "?\(queryParameter)", attributes: [
9494
NSAttributedString.Key.foregroundColor: BKColor.grey.lighten1,
95-
NSAttributedString.Key.font: RobotoFont.regular(with: fontSize)
95+
NSAttributedString.Key.font: UIFont.preferredFont(ofSize: fontSize)
9696
]))
9797
}
9898

View/ServerListTableViewCell.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@ class ServerListTableViewCell: BaseTableViewCell<ServerListTableViewCellViewMode
2525

2626
let addressLabel: UILabel = {
2727
let label = UILabel()
28-
label.font = RobotoFont.medium(with: 14)
28+
label.font = UIFont.preferredFont(ofSize: 14, weight: .medium)
29+
label.adjustsFontForContentSizeCategory = true
2930
label.textColor = BKColor.grey.darken4
3031
label.numberOfLines = 0
3132
return label
3233
}()
3334

3435
let keyLabel: UILabel = {
3536
let label = UILabel()
36-
label.font = RobotoFont.regular(with: 12)
37+
label.font = UIFont.preferredFont(ofSize: 12)
38+
label.adjustsFontForContentSizeCategory = true
3739
label.textColor = BKColor.grey.darken4
3840
label.numberOfLines = 0
3941
return label

notificationContentExtension/NotificationViewController.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ class NotificationViewController: UIViewController, UNNotificationContentExtensi
1515
let label = UILabel()
1616
label.textColor = UIColor(named: "notification_copy_color")
1717
label.text = NSLocalizedString("Copy", comment: "")
18-
label.font = UIFont.systemFont(ofSize: 16)
18+
label.font = UIFont.preferredFont(ofSize: 16)
19+
label.adjustsFontForContentSizeCategory = true
1920
label.textAlignment = .center
2021
return label
2122
}()

0 commit comments

Comments
 (0)