222 lines
8.6 KiB
Swift
222 lines
8.6 KiB
Swift
//
|
||
// RoomTopView.swift
|
||
// yinmeng-ios
|
||
//
|
||
// Created by duoban on 2024/3/6.
|
||
//
|
||
|
||
import UIKit
|
||
import MarqueeLabel
|
||
import FFPopup
|
||
|
||
class RoomTopView: UIView {
|
||
|
||
override init(frame: CGRect) {
|
||
super.init(frame: frame)
|
||
setUILayout()
|
||
|
||
}
|
||
|
||
required init?(coder: NSCoder) {
|
||
fatalError("init(coder:) has not been implemented")
|
||
}
|
||
private func setUILayout(){
|
||
addSubview(superStackView)
|
||
addSubview(settingBnt)
|
||
|
||
superStackView.addSubview(avatarView)
|
||
superStackView.addSubview(nameStackView)
|
||
superStackView.addSubview(colectRoomBtn)
|
||
|
||
|
||
nameStackView.addArrangedSubview(textStackView)
|
||
nameStackView.addArrangedSubview(onlineNumStackView)
|
||
|
||
onlineNumStackView.addArrangedSubview(userIdView)
|
||
onlineNumStackView.addArrangedSubview(greenPointView)
|
||
onlineNumStackView.addArrangedSubview(onlineNumView)
|
||
|
||
textStackView.addArrangedSubview(textView)
|
||
textStackView.addArrangedSubview(giftIconView)
|
||
textStackView.addArrangedSubview(lockIconView)
|
||
|
||
|
||
superStackView.snp.makeConstraints { make in
|
||
make.leading.equalTo(UIDevice.scaleWidth(width: 15))
|
||
make.bottom.equalTo(-UIDevice.scaleWidth(width: 5))
|
||
make.height.equalTo(UIDevice.scaleWidth(width: 34))
|
||
make.width.greaterThanOrEqualTo(10)
|
||
make.trailing.equalTo(colectRoomBtn.snp.trailing).offset(UIDevice.scaleWidth(width: 5))
|
||
}
|
||
settingBnt.snp.makeConstraints { make in
|
||
make.trailing.equalTo(-UIDevice.scaleWidth(width: 13))
|
||
make.centerY.equalTo(nameStackView)
|
||
make.width.height.equalTo(UIDevice.scaleWidth(width: 25))
|
||
}
|
||
avatarView.snp.makeConstraints { make in
|
||
make.leading.top.equalTo(UIDevice.scaleWidth(width: 0))
|
||
|
||
make.width.height.equalTo(nameStackView.snp.height)
|
||
}
|
||
nameStackView.snp.makeConstraints { make in
|
||
make.leading.equalTo(avatarView.snp.trailing).offset((UIDevice.scaleWidth(width: 5)))
|
||
make.bottom.equalTo(0)
|
||
make.height.equalTo(UIDevice.scaleWidth(width: 34))
|
||
}
|
||
|
||
|
||
|
||
colectRoomBtn.snp.makeConstraints { make in
|
||
make.leading.equalTo(textStackView.snp.trailing).offset((UIDevice.scaleWidth(width: 5)))
|
||
make.height.equalTo(UIDevice.scaleWidth(width: 20))
|
||
make.width.equalTo(UIDevice.scaleWidth(width: 40))
|
||
make.centerY.equalTo(superStackView)
|
||
}
|
||
|
||
textView.snp.makeConstraints { make in
|
||
make.width.lessThanOrEqualTo(UIDevice.scaleWidth(width: 90))
|
||
make.height.equalTo(UIDevice.scaleWidth(width: 18))
|
||
}
|
||
greenPointView.snp.makeConstraints { make in
|
||
make.width.height.equalTo(UIDevice.scaleWidth(width: 3))
|
||
|
||
}
|
||
userIdView.snp.makeConstraints { make in
|
||
make.height.equalTo(UIDevice.scaleWidth(width: 16))
|
||
}
|
||
giftIconView.snp.makeConstraints { make in
|
||
|
||
make.width.height.equalTo(UIDevice.scaleWidth(width: 10))
|
||
}
|
||
lockIconView.snp.makeConstraints { make in
|
||
make.width.height.equalTo(UIDevice.scaleWidth(width: 18))
|
||
}
|
||
}
|
||
|
||
//MARK: - bntTarget
|
||
@objc func colectRoomAction(){
|
||
colectRoomBtn.isSelected = !colectRoomBtn.isSelected
|
||
let width:CGFloat = !colectRoomBtn.isSelected ? 40 : 50
|
||
colectRoomBtn.snp.updateConstraints { make in
|
||
make.width.equalTo(UIDevice.scaleWidth(width: width))
|
||
}
|
||
}
|
||
@objc func settingBntAction(){
|
||
let quitView = RoomQuitView(frame: .zero)
|
||
quitView.delegate = self
|
||
quitView.frame = CGRect(x: ScreenWidth, y: 0, width: ScreenWidth, height: ScreenHeight)
|
||
keyWindow.addSubview(quitView)
|
||
UIView.animate(withDuration: 0.1) {
|
||
quitView.frame = CGRect(x: 0, y: 0, width:ScreenWidth, height: ScreenHeight)
|
||
}
|
||
}
|
||
//MARK: - 懒加载
|
||
private lazy var settingBnt:UIButton = {
|
||
let _settingBtn = UIButton.getCustomBtn(image: UIImage(named: "yin_room_top_right"))
|
||
_settingBtn.setBtnClickRadius = UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8)
|
||
_settingBtn.addTarget(self, action: #selector(settingBntAction), for: .touchUpInside)
|
||
return _settingBtn
|
||
}()
|
||
private lazy var colectRoomBtn:UIButton = {
|
||
let image = UIImage.image(color: ThemeColor(hexStr: "#FFDA24"))
|
||
let _colectRoomBtn = UIButton.getCustomBtn(text: "收藏",selectedText:"已收藏",font: UIFont.getScaleFont(ofSize: 11, weight: .medium),color: .white,bgImage: image)
|
||
_colectRoomBtn.layer.cornerRadius = UIDevice.scaleWidth(width: 10)
|
||
_colectRoomBtn.layer.masksToBounds = true
|
||
_colectRoomBtn.contentEdgeInsets = UIEdgeInsets(top: 0, left: UIDevice.scaleWidth(width: 7), bottom: 0, right: UIDevice.scaleWidth(width: 7))
|
||
_colectRoomBtn.addTarget(self, action: #selector(colectRoomAction), for: .touchUpInside)
|
||
// _colectRoomBtn.isHidden = true
|
||
return _colectRoomBtn
|
||
}()
|
||
private lazy var nameStackView:UIStackView = {
|
||
let _nameStackView = UIStackView()
|
||
_nameStackView.axis = .vertical
|
||
_nameStackView.distribution = .fill
|
||
_nameStackView.alignment = .leading
|
||
return _nameStackView
|
||
}()
|
||
private lazy var textStackView:UIStackView = {
|
||
let _textStackView = UIStackView()
|
||
_textStackView.axis = .horizontal
|
||
_textStackView.distribution = .fill
|
||
_textStackView.alignment = .center
|
||
_textStackView.spacing = UIDevice.scaleWidth(width: 5)
|
||
return _textStackView
|
||
}()
|
||
private lazy var textView:MarqueeLabel = {
|
||
let _textView = MarqueeLabel()
|
||
_textView.text = "我是一个小萌新"
|
||
_textView.speed = .duration(8)
|
||
_textView.fadeLength = UIDevice.scaleWidth(width: 6)
|
||
_textView.font = UIFont.getScaleFont(ofSize: 12, weight: .medium)
|
||
_textView.textColor = .white
|
||
// _textView.isUserInteractionEnabled = true
|
||
return _textView
|
||
}()
|
||
private lazy var giftIconView:UIImageView = {
|
||
let _giftIconView = UIImageView()
|
||
_giftIconView.image = UIImage(named: "yin_room_top_gift_icon")
|
||
_giftIconView.isUserInteractionEnabled = true
|
||
return _giftIconView
|
||
}()
|
||
private lazy var lockIconView:UIImageView = {
|
||
let _lockIconView = UIImageView()
|
||
_lockIconView.image = UIImage(named: "yin_room_top_lock_icon")
|
||
_lockIconView.isUserInteractionEnabled = true
|
||
// _lockIconView.isHidden = true
|
||
return _lockIconView
|
||
}()
|
||
|
||
private lazy var onlineNumStackView:UIStackView = {
|
||
let _onlineNumStackView = UIStackView()
|
||
_onlineNumStackView.axis = .horizontal
|
||
_onlineNumStackView.distribution = .fill
|
||
_onlineNumStackView.alignment = .center
|
||
_onlineNumStackView.spacing = UIDevice.scaleWidth(width: 2)
|
||
return _onlineNumStackView
|
||
}()
|
||
private lazy var greenPointView:UIView = {
|
||
let _greenPointView = UIView()
|
||
_greenPointView.backgroundColor = ThemeColor(hexStr: "#3EFED7")
|
||
_greenPointView.layer.cornerRadius = UIDevice.scaleWidth(width: 3)/2
|
||
// _greenPointView.layer.masksToBounds = true
|
||
|
||
return _greenPointView
|
||
}()
|
||
private lazy var userIdView:UILabel = {
|
||
let _userIdView = UILabel.getCustomLabel(text:"ID:837283",font: UIFont.getScaleFont(ofSize: 10, weight: .regular),color: .white)
|
||
return _userIdView
|
||
}()
|
||
private lazy var onlineNumView:UILabel = {
|
||
let _onlineNumView = UILabel.getCustomLabel(text:"100",font: UIFont.getScaleFont(ofSize: 10, weight: .regular),color: .white)
|
||
|
||
return _onlineNumView
|
||
}()
|
||
private lazy var avatarView:UIImageView = {
|
||
let _avatarView = UIImageView()
|
||
_avatarView.isUserInteractionEnabled = true
|
||
_avatarView.layer.masksToBounds = true
|
||
_avatarView.layer.cornerRadius = UIDevice.scaleWidth(width: 17)
|
||
_avatarView.contentMode = .scaleAspectFill
|
||
_avatarView.backgroundColor = .yellow
|
||
return _avatarView
|
||
}()
|
||
private lazy var superStackView:UIView = {
|
||
let _superStackView = UIView()
|
||
_superStackView.backgroundColor = UIColor(white: 1, alpha: 0.1)
|
||
_superStackView.layer.cornerRadius = UIDevice.scaleWidth(width: 17)
|
||
return _superStackView
|
||
}()
|
||
|
||
|
||
|
||
}
|
||
|
||
extension RoomTopView:RoomQuitViewProtocol{
|
||
func didChooseRoomWithModel(roomModel: RoomQuitModel?) {
|
||
|
||
}
|
||
func didClickTypeWithModel(clickModel: RoomQuitItemModel) {
|
||
|
||
}
|
||
}
|