Files
real-e-party-iOS/YuMi/E-P/NewMessage/EPFriendFollowingFans.swift
edwinQQQ c8173bf034 refactor: 移除 Core Data 相关代码并添加新的消息列表视图控制器
主要变更:
1. 从 AppDelegate 中移除 Core Data 相关的属性和方法,简化应用结构。
2. 新增 EPBaseListViewController 作为消息列表的基础类,提供通用的表视图功能。
3. 添加 EPMessageListVC、EPFriendListVC、EPFollowingListVC 和 EPFansListVC,分别用于展示消息、朋友、关注和粉丝列表。
4. 引入 EPMessageSegmentView 以支持消息主界面的分段控制。

此更新旨在提升代码的可维护性,简化数据管理,并增强用户界面的功能性和交互性。
2025-10-20 11:25:33 +08:00

127 lines
4.7 KiB
Swift

import UIKit
final class EPFriendListVC: EPBaseListViewController<EPUserBriefCell> {
override func viewDidLoad() { super.viewDidLoad(); simulateItems(6) }
}
final class EPFollowingListVC: EPBaseListViewController<EPUserBriefCell> {
override func viewDidLoad() { super.viewDidLoad(); simulateItems(10) }
}
final class EPFansListVC: EPBaseListViewController<EPUserBriefCell> {
override func viewDidLoad() { super.viewDidLoad(); simulateItems(12) }
}
final class EPUserBriefCell: UITableViewCell {
private let avatar = UIImageView()
private let nameLabel = UILabel()
private let subtitleLabel = UILabel()
private let followButton = EPFollowButton()
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 = "Welcome to play"
contentView.addSubview(avatar)
contentView.addSubview(nameLabel)
contentView.addSubview(subtitleLabel)
contentView.addSubview(followButton)
avatar.translatesAutoresizingMaskIntoConstraints = false
nameLabel.translatesAutoresizingMaskIntoConstraints = false
subtitleLabel.translatesAutoresizingMaskIntoConstraints = false
followButton.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),
followButton.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -16),
followButton.centerYAnchor.constraint(equalTo: contentView.centerYAnchor),
followButton.widthAnchor.constraint(equalToConstant: 120),
followButton.heightAnchor.constraint(equalToConstant: 40)
])
followButton.setFollowed(false)
}
}
final class EPFollowButton: UIButton {
private var isFollowedState: Bool = false
override init(frame: CGRect) { super.init(frame: frame); setup() }
required init?(coder: NSCoder) { super.init(coder: coder); setup() }
private func setup() {
titleLabel?.font = .systemFont(ofSize: 18, weight: .semibold)
layer.cornerRadius = 20
layer.masksToBounds = true
addTarget(self, action: #selector(onTap), for: .touchUpInside)
}
func setFollowed(_ followed: Bool) {
isFollowedState = followed
if followed {
setTitle("Followed", for: .normal)
backgroundColor = .clear
layer.borderWidth = 1
layer.borderColor = UIColor.systemPurple.withAlphaComponent(0.6).cgColor
setTitleColor(UIColor.systemPurple.withAlphaComponent(0.9), for: .normal)
} else {
setTitle("Follow", for: .normal)
layer.borderWidth = 0
setTitleColor(.white, for: .normal)
setGradientBackground()
}
}
@objc private func onTap() { setFollowed(!isFollowedState) }
private func setGradientBackground() {
let gradient = CAGradientLayer()
gradient.colors = [UIColor.systemPink.cgColor, UIColor.systemPurple.cgColor]
gradient.startPoint = CGPoint(x: 0, y: 0.5)
gradient.endPoint = CGPoint(x: 1, y: 0.5)
gradient.frame = bounds
gradient.cornerRadius = layer.cornerRadius
layer.sublayers?.removeAll(where: { $0 is CAGradientLayer })
layer.insertSublayer(gradient, at: 0)
}
override func layoutSubviews() {
super.layoutSubviews()
if !isFollowedState { setGradientBackground() }
}
}