163 lines
5.7 KiB
Plaintext
163 lines
5.7 KiB
Plaintext
//
|
||
// EPAboutUsViewController.swift
|
||
// YuMi
|
||
//
|
||
// Created by AI on 2025-01-28.
|
||
//
|
||
|
||
import UIKit
|
||
import SnapKit
|
||
|
||
/// About Us 页面
|
||
/// 展示应用图标和版本信息
|
||
class EPAboutUsViewController: BaseViewController {
|
||
|
||
// MARK: - UI Components
|
||
|
||
private lazy var appIconImageView: UIImageView = {
|
||
let imageView = UIImageView()
|
||
imageView.contentMode = .scaleAspectFit
|
||
imageView.layer.cornerRadius = 20
|
||
imageView.layer.masksToBounds = true
|
||
// 获取应用图标
|
||
if let iconName = Bundle.main.object(forInfoDictionaryKey: "CFBundleIconName") as? String {
|
||
imageView.image = UIImage(named: iconName)
|
||
} else if let icons = Bundle.main.object(forInfoDictionaryKey: "CFBundleIcons") as? [String: Any],
|
||
let primaryIcon = icons["CFBundlePrimaryIcon"] as? [String: Any],
|
||
let iconFiles = primaryIcon["CFBundleIconFiles"] as? [String],
|
||
let lastIcon = iconFiles.last {
|
||
imageView.image = UIImage(named: lastIcon)
|
||
} else {
|
||
// 使用占位图标
|
||
imageView.image = UIImage(named: "pi_app_logo_new_bg")
|
||
}
|
||
return imageView
|
||
}()
|
||
|
||
private lazy var appNameLabel: UILabel = {
|
||
let label = UILabel()
|
||
label.text = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String
|
||
?? Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String
|
||
?? "YuMi"
|
||
label.textColor = .white
|
||
label.font = .systemFont(ofSize: 24, weight: .bold)
|
||
label.textAlignment = .center
|
||
return label
|
||
}()
|
||
|
||
private lazy var versionLabel: UILabel = {
|
||
let label = UILabel()
|
||
let version = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String ?? "1.0.0"
|
||
let build = Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion") as? String ?? "1"
|
||
label.text = "Version \(version) (\(build))"
|
||
label.textColor = UIColor.white.withAlphaComponent(0.7)
|
||
label.font = .systemFont(ofSize: 16)
|
||
label.textAlignment = .center
|
||
return label
|
||
}()
|
||
|
||
// MARK: - Lifecycle
|
||
|
||
override func viewDidLoad() {
|
||
super.viewDidLoad()
|
||
setupNavigationBar()
|
||
setupUI()
|
||
}
|
||
|
||
override func viewWillAppear(_ animated: Bool) {
|
||
super.viewWillAppear(animated)
|
||
navigationController?.setNavigationBarHidden(false, animated: animated)
|
||
}
|
||
|
||
// MARK: - Setup
|
||
|
||
private func setupNavigationBar() {
|
||
title = YMLocalizedString("EPEditSetting.AboutUs")
|
||
|
||
// 配置导航栏外观(iOS 13+)
|
||
let appearance = UINavigationBarAppearance()
|
||
appearance.configureWithOpaqueBackground()
|
||
appearance.backgroundColor = UIColor(hex: "#0C0527")
|
||
appearance.titleTextAttributes = [
|
||
.foregroundColor: UIColor.white,
|
||
.font: UIFont.systemFont(ofSize: 18, weight: .medium)
|
||
]
|
||
appearance.shadowColor = .clear // 移除底部分割线
|
||
|
||
navigationController?.navigationBar.standardAppearance = appearance
|
||
navigationController?.navigationBar.scrollEdgeAppearance = appearance
|
||
navigationController?.navigationBar.compactAppearance = appearance
|
||
navigationController?.navigationBar.tintColor = .white // 返回按钮颜色
|
||
|
||
// 隐藏返回按钮文字,只保留箭头
|
||
navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
|
||
}
|
||
|
||
private func setupUI() {
|
||
view.backgroundColor = UIColor(hex: "#0C0527")
|
||
|
||
// 创建容器视图
|
||
let containerView = UIView()
|
||
view.addSubview(containerView)
|
||
|
||
// 添加 UI 组件到容器
|
||
containerView.addSubview(appIconImageView)
|
||
containerView.addSubview(appNameLabel)
|
||
containerView.addSubview(versionLabel)
|
||
|
||
// 布局容器(垂直居中)
|
||
containerView.snp.makeConstraints { make in
|
||
make.centerY.equalTo(view).offset(-50) // 稍微偏上
|
||
make.leading.trailing.equalTo(view).inset(40)
|
||
}
|
||
|
||
// 应用图标
|
||
appIconImageView.snp.makeConstraints { make in
|
||
make.top.equalTo(containerView)
|
||
make.centerX.equalTo(containerView)
|
||
make.size.equalTo(100)
|
||
}
|
||
|
||
// 应用名称
|
||
appNameLabel.snp.makeConstraints { make in
|
||
make.top.equalTo(appIconImageView.snp.bottom).offset(24)
|
||
make.leading.trailing.equalTo(containerView)
|
||
}
|
||
|
||
// 版本号
|
||
versionLabel.snp.makeConstraints { make in
|
||
make.top.equalTo(appNameLabel.snp.bottom).offset(12)
|
||
make.leading.trailing.equalTo(containerView)
|
||
}
|
||
}
|
||
}
|
||
|
||
// MARK: - UIColor Extension
|
||
|
||
private extension UIColor {
|
||
convenience init(hex: String) {
|
||
let hex = hex.trimmingCharacters(in: CharacterSet.alphanumerics.inverted)
|
||
var int: UInt64 = 0
|
||
Scanner(string: hex).scanHexInt64(&int)
|
||
let a, r, g, b: UInt64
|
||
switch hex.count {
|
||
case 3: // RGB (12-bit)
|
||
(a, r, g, b) = (255, (int >> 8) * 17, (int >> 4 & 0xF) * 17, (int & 0xF) * 17)
|
||
case 6: // RGB (24-bit)
|
||
(a, r, g, b) = (255, int >> 16, int >> 8 & 0xFF, int & 0xFF)
|
||
case 8: // ARGB (32-bit)
|
||
(a, r, g, b) = (int >> 24, int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF)
|
||
default:
|
||
(a, r, g, b) = (1, 1, 1, 0)
|
||
}
|
||
|
||
self.init(
|
||
red: CGFloat(r) / 255,
|
||
green: CGFloat(g) / 255,
|
||
blue: CGFloat(b) / 255,
|
||
alpha: CGFloat(a) / 255
|
||
)
|
||
}
|
||
}
|
||
|