// // MPPositive_HomeSingleCollectionViewCell.swift // relax.offline.mp3.music // // Created by Mr.Zhou on 2024/7/4. // import UIKit class MPPositive_HomeSingleCollectionViewCell: UICollectionViewCell { ///封面图片 private lazy var coverImageView:UIImageView = { let imageView:UIImageView = .init() imageView.contentMode = .scaleAspectFill imageView.layer.masksToBounds = true imageView.layer.cornerRadius = 10*width return imageView }() ///标题 private lazy var titleLabel:UILabel = createLabel(font: .systemFont(ofSize: 14*width, weight: .regular), textColor: .white, textAlignment: .left) ///副标题 private lazy var subtitleLabel:UILabel = createLabel(font: .systemFont(ofSize: 12*width, weight: .regular), textColor: .init(hex: "#FFFFFF", alpha: 0.6), textAlignment: .left) ///更多按钮 private lazy var moreBtn:UIButton = { let btn:UIButton = .init() btn.setBackgroundImage(UIImage(named: "Song_More'logo"), for: .normal) btn.addTarget(self, action: #selector(moreActionClick(_ :)), for: .touchUpInside) return btn }() var moreBlock:(() -> Void)? var itemViewModel:MPPositive_BrowseItemViewModel!{ didSet{ itemViewModel.setUrltoImage(coverImageView) titleLabel.text = itemViewModel.title subtitleLabel.text = itemViewModel.subtitle } } override init(frame: CGRect) { super.init(frame: frame) confirgue() } required init?(coder: NSCoder) { super.init(coder: coder) } private func confirgue() { backgroundColor = .clear layer.masksToBounds = true layer.cornerRadius = 16*width addSubview(coverImageView) coverImageView.snp.makeConstraints { make in make.width.height.equalTo(58*width) make.left.equalToSuperview().offset(18*width) make.centerY.equalToSuperview() } addSubview(moreBtn) moreBtn.snp.makeConstraints { make in make.width.height.equalTo(24*width) make.centerY.equalTo(coverImageView.snp.centerY) make.right.equalToSuperview().offset(-5*width) } addSubview(titleLabel) titleLabel.snp.makeConstraints { make in make.top.equalTo(coverImageView.snp.top).offset(10*width) make.left.equalTo(coverImageView.snp.right).offset(12*width) make.right.equalTo(moreBtn.snp.left).offset(-12*width) } addSubview(subtitleLabel) subtitleLabel.snp.makeConstraints { make in make.bottom.equalTo(coverImageView.snp.bottom).offset(-10*width) make.left.right.equalTo(titleLabel) } } //点击更多 @objc private func moreActionClick(_ sender:UIButton) { guard MP_NetWorkManager.shared.netWorkStatu == .reachable else { MP_HUD.text("Weak connection.", delay: 2.0, completion: nil) return } guard moreBlock != nil else { return } moreBlock!() } }