实现权限驱动的首页 Tab 并对齐 Android
This commit is contained in:
77
suixinkan/UI/Home/Views/HomeWorkStatusCardView.swift
Normal file
77
suixinkan/UI/Home/Views/HomeWorkStatusCardView.swift
Normal file
@ -0,0 +1,77 @@
|
||||
//
|
||||
// HomeWorkStatusCardView.swift
|
||||
// suixinkan
|
||||
//
|
||||
|
||||
import SnapKit
|
||||
import UIKit
|
||||
|
||||
/// 首页在线状态与倒计时卡片。
|
||||
final class HomeWorkStatusCardView: UIView {
|
||||
|
||||
var onOnlineTap: (() -> Void)?
|
||||
var onReminderTap: (() -> Void)?
|
||||
|
||||
private let onlineButton = UIButton(type: .system)
|
||||
private let countdownLabel = UILabel()
|
||||
private let reminderButton = UIButton(type: .system)
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
backgroundColor = .white
|
||||
layer.cornerRadius = 10
|
||||
|
||||
onlineButton.titleLabel?.font = .systemFont(ofSize: 12, weight: .medium)
|
||||
onlineButton.layer.cornerRadius = 4
|
||||
onlineButton.contentEdgeInsets = UIEdgeInsets(top: 6, left: 12, bottom: 6, right: 12)
|
||||
onlineButton.addTarget(self, action: #selector(onlineTapped), for: .touchUpInside)
|
||||
|
||||
countdownLabel.font = .systemFont(ofSize: 16, weight: .medium)
|
||||
countdownLabel.textColor = AppColor.primary
|
||||
|
||||
reminderButton.titleLabel?.font = .systemFont(ofSize: 16, weight: .medium)
|
||||
reminderButton.setTitleColor(AppColor.primary, for: .normal)
|
||||
reminderButton.addTarget(self, action: #selector(reminderTapped), for: .touchUpInside)
|
||||
|
||||
addSubview(onlineButton)
|
||||
addSubview(countdownLabel)
|
||||
addSubview(reminderButton)
|
||||
|
||||
onlineButton.snp.makeConstraints { make in
|
||||
make.leading.equalToSuperview().offset(15)
|
||||
make.centerY.equalToSuperview()
|
||||
}
|
||||
countdownLabel.snp.makeConstraints { make in
|
||||
make.center.equalToSuperview()
|
||||
}
|
||||
reminderButton.snp.makeConstraints { make in
|
||||
make.trailing.equalToSuperview().offset(-15)
|
||||
make.centerY.equalToSuperview()
|
||||
}
|
||||
snp.makeConstraints { make in
|
||||
make.height.equalTo(52)
|
||||
}
|
||||
}
|
||||
|
||||
@available(*, unavailable)
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
|
||||
func apply(isOnline: Bool, countdownText: String, reminderMinutes: Int) {
|
||||
onlineButton.setTitle(isOnline ? "在线" : "离线", for: .normal)
|
||||
if isOnline {
|
||||
onlineButton.backgroundColor = UIColor(hex: 0x22C55E)
|
||||
onlineButton.setTitleColor(UIColor(hex: 0xF0FDF4), for: .normal)
|
||||
} else {
|
||||
onlineButton.backgroundColor = UIColor(hex: 0xF4F4F4)
|
||||
onlineButton.setTitleColor(UIColor(hex: 0x7B8EAA), for: .normal)
|
||||
}
|
||||
countdownLabel.text = countdownText
|
||||
let reminderTitle = reminderMinutes == 0 ? "不提醒" : "提前\(reminderMinutes)分钟"
|
||||
reminderButton.setTitle(reminderTitle, for: .normal)
|
||||
}
|
||||
|
||||
@objc private func onlineTapped() { onOnlineTap?() }
|
||||
@objc private func reminderTapped() { onReminderTap?() }
|
||||
}
|
||||
Reference in New Issue
Block a user