设置页显示版本号

This commit is contained in:
Fin 2024-11-15 10:45:15 +08:00
parent d3053ad875
commit 6badbec561
3 changed files with 29 additions and 8 deletions

View File

@ -28,9 +28,7 @@ class MessageSettingsViewController: BaseViewController<MessageSettingsViewModel
tableView.register(SpacerCell.self, forCellReuseIdentifier: "\(SpacerCell.self)")
tableView.register(DonateCell.self, forCellReuseIdentifier: "\(DonateCell.self)")
tableView.estimatedSectionFooterHeight = 10
tableView.estimatedSectionHeaderHeight = 10
tableView.sectionFooterHeight = UITableView.automaticDimension
tableView.sectionHeaderHeight = UITableView.automaticDimension
let footer = MessageSettingFooter()
@ -316,4 +314,20 @@ extension MessageSettingsViewController: UITableViewDelegate {
footerView.titleLabel.text = footer
return footerView
}
/// FUCK iOS, insetGrouped tableView.sectionFooterHeight = UITableView.automaticDimension BUG
///
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
guard self.footers.count > section, let footer = self.footers[section] else { return 10 }
// 16 tableView 12 uilabel
let size = CGSize(width: tableView.frame.width - 16 * 2 - 12 * 2, height: .greatestFiniteMagnitude)
let rect = (footer as NSString).boundingRect(
with: size,
options: [.usesLineFragmentOrigin],
attributes: [.font: UIFont.preferredFont(ofSize: 12)],
context: nil
)
// 8: top offset, 6bottom offset
return rect.height + 8 + 6
}
}

View File

@ -10,20 +10,27 @@ import UIKit
class MessageSettingFooter: UITextView, UITextViewDelegate {
init() {
super.init(frame: CGRect(x: 0, y: 0, width: 0, height: 40), textContainer: .none)
super.init(frame: CGRect(x: 0, y: 0, width: 0, height: 80), textContainer: .none)
self.backgroundColor = UIColor.clear
self.isEditable = false
self.delegate = self
self.font = UIFont.preferredFont(ofSize: 12)
self.textColor = BKColor.grey.darken1
//
let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
// build
let buildVersion = Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? ""
let attr = NSMutableAttributedString(string: NSLocalizedString("privacyPolicy"), attributes: [.link: "privacyPolicy"])
let attr = NSMutableAttributedString(string: "Version \(appVersion) (Build \(buildVersion))\n", attributes: [.font: UIFont.preferredFont(ofSize: 12), .foregroundColor: BKColor.grey.darken1])
attr.append(NSAttributedString(string: NSLocalizedString("privacyPolicy"), attributes: [.link: "privacyPolicy"]))
attr.append(NSAttributedString(string: " · "))
attr.append(NSAttributedString(string: NSLocalizedString("userAgreement"), attributes: [.link: "userAgreement"]))
attr.append(NSAttributedString(string: " · "))
attr.append(NSAttributedString(string: NSLocalizedString("restoreSubscription"), attributes: [.link: "restoreSubscription"]))
let style = NSMutableParagraphStyle()
style.lineSpacing = 6
attr.addAttribute(.paragraphStyle, value: style, range: NSRange(location: 0, length: attr.length))
self.attributedText = attr
self.linkTextAttributes = [.foregroundColor: BKColor.grey.darken1, .underlineStyle: NSUnderlineStyle.single.rawValue]
self.textAlignment = .center

View File

@ -48,9 +48,9 @@ class SettingSectionFooter: UIView {
self.addSubview(titleLabel)
titleLabel.snp.makeConstraints { make in
make.top.equalTo(8)
make.bottom.equalTo(-6)
// make.bottom.equalTo(-6)
make.left.equalTo(12)
make.right.equalTo(-8)
make.right.equalTo(-12)
}
}