prank/Funny_sounds/Home/V/FS_ClassificationCollectionCell.swift
2024-09-03 09:38:34 +08:00

101 lines
3.1 KiB
Swift

//
// FS_ClassificationCollectionCell.swift
// Funny_sounds
//
// Created by 16 on 2024/8/15.
//
import UIKit
import SDWebImage
class FS_ClassificationCollectionCell: UICollectionViewCell {
lazy var bgImageV:UIImageView = {
let bgImageV = UIImageView()
bgImageV.image = UIImage(named: "classbg")
bgImageV.contentMode = .scaleToFill
return bgImageV
}()
lazy var conentImageV:UIImageView = {
let conentImageV = UIImageView()
conentImageV.image = UIImage(named: "collectionImageV")
conentImageV.contentMode = .scaleAspectFit
conentImageV.layer.cornerRadius = 40
conentImageV.clipsToBounds = true
conentImageV.contentMode = .scaleToFill
return conentImageV
}()
lazy var nameLabel: BorderedLabel = {
let nameLabel = BorderedLabel()
nameLabel.text = "Air Horn"
nameLabel.font = UIFont(name: "PaytoneOne-Regular", size: 16)
nameLabel.textColor = .white //
nameLabel.numberOfLines = 0
nameLabel.textAlignment = .center
//
let shadow = NSShadow()
shadow.shadowColor = UIColor.black.withAlphaComponent(1.0) //
shadow.shadowOffset = CGSize(width: 0, height: 6) // 2
shadow.shadowBlurRadius = 0 //
//
let attributedText = NSMutableAttributedString(string: nameLabel.text!)
attributedText.addAttribute(.shadow, value: shadow, range: NSRange(location: 0, length: nameLabel.text!.count))
nameLabel.attributedText = attributedText
nameLabel.sizeToFit()
return nameLabel
}()
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override init(frame: CGRect) {
super.init(frame: frame)
setUI()
contentView.backgroundColor = .clear
}
// MARK: -
func setUI(){
self.addSubview(bgImageV)
self.addSubview(conentImageV)
self.addSubview(nameLabel)
bgImageV.snp.makeConstraints { make in
make.width.height.equalTo(100)
make.top.equalToSuperview().offset(5)
make.centerX.equalToSuperview()
}
conentImageV.snp.makeConstraints { make in
make.centerX.centerY.equalTo(bgImageV)
make.height.width.equalTo(80)
}
nameLabel.snp.makeConstraints { make in
make.top.equalTo(conentImageV.snp.bottom).offset(8)
make.width.equalToSuperview()
}
}
var model:AudioFile?{
didSet{
if let imageURL = URL(string: model?.preUrl ?? "") {
// wpImagV.sd_setImage(with: imageURL, completed: nil)
conentImageV.sd_setImage(with: imageURL, placeholderImage: UIImage(named: "collectionImageV"))
}
nameLabel.text = model?.title
}
}
}