
主要变更: 1. 从 AppDelegate 中移除 Core Data 相关的属性和方法,简化应用结构。 2. 新增 EPBaseListViewController 作为消息列表的基础类,提供通用的表视图功能。 3. 添加 EPMessageListVC、EPFriendListVC、EPFollowingListVC 和 EPFansListVC,分别用于展示消息、朋友、关注和粉丝列表。 4. 引入 EPMessageSegmentView 以支持消息主界面的分段控制。 此更新旨在提升代码的可维护性,简化数据管理,并增强用户界面的功能性和交互性。
91 lines
3.5 KiB
Swift
91 lines
3.5 KiB
Swift
import UIKit
|
|
|
|
final class EPMessageListVC: EPBaseListViewController<EPMessageCell> {
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
simulateItems(8)
|
|
}
|
|
}
|
|
|
|
// MARK: - Cell
|
|
final class EPMessageCell: UITableViewCell {
|
|
private let avatar = UIImageView()
|
|
private let nameLabel = UILabel()
|
|
private let subtitleLabel = UILabel()
|
|
private let timeLabel = UILabel()
|
|
private let unreadView = UILabel()
|
|
|
|
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
|
|
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
|
setup()
|
|
}
|
|
required init?(coder: NSCoder) { super.init(coder: coder); setup() }
|
|
|
|
private func setup() {
|
|
selectionStyle = .none
|
|
backgroundColor = .clear
|
|
|
|
avatar.contentMode = .scaleAspectFill
|
|
avatar.layer.cornerRadius = 24
|
|
avatar.layer.masksToBounds = true
|
|
avatar.image = UIImage(named: "pi_login_new_logo")
|
|
|
|
nameLabel.font = .systemFont(ofSize: 20, weight: .semibold)
|
|
nameLabel.textColor = .white
|
|
nameLabel.text = "Momoyy"
|
|
|
|
subtitleLabel.font = .systemFont(ofSize: 16)
|
|
subtitleLabel.textColor = UIColor.white.withAlphaComponent(0.6)
|
|
subtitleLabel.text = "Nice to meet you"
|
|
|
|
timeLabel.font = .systemFont(ofSize: 14)
|
|
timeLabel.textColor = UIColor.white.withAlphaComponent(0.5)
|
|
timeLabel.text = "11:03"
|
|
|
|
unreadView.backgroundColor = UIColor.systemRed
|
|
unreadView.textColor = .white
|
|
unreadView.font = .systemFont(ofSize: 12, weight: .bold)
|
|
unreadView.textAlignment = .center
|
|
unreadView.layer.cornerRadius = 12
|
|
unreadView.layer.masksToBounds = true
|
|
unreadView.text = "99+"
|
|
|
|
contentView.addSubview(avatar)
|
|
contentView.addSubview(nameLabel)
|
|
contentView.addSubview(subtitleLabel)
|
|
contentView.addSubview(timeLabel)
|
|
contentView.addSubview(unreadView)
|
|
|
|
avatar.translatesAutoresizingMaskIntoConstraints = false
|
|
nameLabel.translatesAutoresizingMaskIntoConstraints = false
|
|
subtitleLabel.translatesAutoresizingMaskIntoConstraints = false
|
|
timeLabel.translatesAutoresizingMaskIntoConstraints = false
|
|
unreadView.translatesAutoresizingMaskIntoConstraints = false
|
|
|
|
NSLayoutConstraint.activate([
|
|
avatar.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 16),
|
|
avatar.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
|
|
avatar.widthAnchor.constraint(equalToConstant: 48),
|
|
avatar.heightAnchor.constraint(equalToConstant: 48),
|
|
|
|
nameLabel.leadingAnchor.constraint(equalTo: avatar.trailingAnchor, constant: 12),
|
|
nameLabel.topAnchor.constraint(equalTo: avatar.topAnchor, constant: -2),
|
|
|
|
subtitleLabel.leadingAnchor.constraint(equalTo: nameLabel.leadingAnchor),
|
|
subtitleLabel.topAnchor.constraint(equalTo: nameLabel.bottomAnchor, constant: 6),
|
|
|
|
timeLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -16),
|
|
timeLabel.topAnchor.constraint(equalTo: nameLabel.topAnchor),
|
|
|
|
unreadView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -16),
|
|
unreadView.centerYAnchor.constraint(equalTo: subtitleLabel.centerYAnchor),
|
|
unreadView.widthAnchor.constraint(greaterThanOrEqualToConstant: 40),
|
|
unreadView.heightAnchor.constraint(equalToConstant: 24)
|
|
])
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|