Files
yingmeng-ios-switf/yinmeng-ios/Modules/Chat/View/ChatNavView.swift
2024-03-01 15:39:53 +08:00

119 lines
3.3 KiB
Swift

//
// ChatNavView.swift
// yinmeng-ios
//
// Created by MaiMang on 2024/3/1.
//
import UIKit
class ChatNavView: BaseView {
var uid:String = ""
var isLike:Bool? {
didSet {
self.likeBtn.isHidden = isLike ?? false
}
}
var name:String? {
didSet {
self.titleLb.text = name
}
}
override func loadSubViews() {
addSubview(backBtn)
addSubview(titleLb)
addSubview(likeBtn)
addSubview(optBtn)
backBtn.snp.makeConstraints { make in
make.size.equalTo(CGSize(width: 18, height: 18))
make.left.equalToSuperview().offset(16)
make.bottom.equalTo(self).offset(-13)
}
titleLb.snp.makeConstraints { make in
make.centerX.equalTo(self)
make.centerY.equalTo(backBtn)
}
likeBtn.snp.makeConstraints { make in
make.size.equalTo(CGSize(width: 48, height: 21))
make.centerY.equalTo(backBtn)
make.right.equalTo(optBtn.snp.left).offset(-10)
}
optBtn.snp.makeConstraints { make in
make.size.equalTo(CGSize(width: 18, height: 18))
make.right.equalTo(self).offset(-16)
make.centerY.equalTo(backBtn)
}
}
private lazy var backBtn: UIButton = {
let button = UIButton(type: .custom)
button.setImage(UIImage(named: "chat_back"), for: .normal)
button.setImage(UIImage(named: "chat_back"), for: .selected)
button.addTarget(self, action: #selector(backClick), for: .touchUpInside)
return button
}()
private lazy var titleLb: UILabel = {
let label = UILabel()
label.textColor = ThemeColor(hexStr: "#2B2D33")
label.font = UIFont.systemFont(ofSize: 16, weight: .medium)
label.textAlignment = .center
return label
}()
private lazy var likeBtn: UIButton = {
let button = UIButton(type: .custom)
button.setTitle("关注", for: .normal)
button.setTitleColor(ThemeColor(hexStr: "#FFDA24"), for: .normal)
button.titleLabel?.font = UIFont.systemFont(ofSize: 12, weight: .medium)
button.layer.masksToBounds = true
button.layer.cornerRadius = 11
button.layer.borderWidth = 0.5
button.layer.borderColor = ThemeColor(hexStr: "#FFDA24").cgColor
button.addTarget(self, action: #selector(likeClick), for: .touchUpInside)
return button
}()
private lazy var optBtn: UIButton = {
let button = UIButton(type: .custom)
button.setImage(UIImage(named: "chat_opt"), for: .normal)
button.setImage(UIImage(named: "chat_opt"), for: .selected)
button.addTarget(self, action: #selector(optClick), for: .touchUpInside)
return button
}()
@objc func optClick() {
let alertController = UIAlertController(title: nil,
message: nil,
preferredStyle: .actionSheet)
alertController.addAction(UIAlertAction(title: "举报", style: .default, handler: { action in
HUDTool.show(with: "举报成功, 我们将尽快处理")
}))
alertController.addAction(UIAlertAction(title: "取消", style: .cancel, handler: { action in
}))
YMRequestX.topViewController()?.present(alertController, animated: true, completion: nil)
}
@objc func likeClick() {
let params:[String: Any] = ["uid": AuthManager.userUid, "ticket": AuthManager.ticket, "type":"1", "likedUid": uid]
RequestPost(path: "fans/like", parma: params) { _ in
self.likeBtn.isHidden = true
} fail: { code, msg in
HUDTool.show(with: msg)
}
}
@objc func backClick() {
YMRequestX.topViewController()?.navigationController?.popViewController(animated: true)
}
}