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

133 lines
4.0 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// FS_HomeCollectionViewCell.swift
// Funny_sounds
//
// Created by 16 on 2024/8/15.
//
import UIKit
import SnapKit
import SDWebImage
class FS_HomeCollectionViewCell: UICollectionViewCell {
lazy var bgImageV:UIImageView = {
let bgImageV = UIImageView()
bgImageV.image = UIImage(named: "collectionBgV")
bgImageV.contentMode = .scaleToFill
return bgImageV
}()
lazy var conentImageV:UIImageView = {
let conentImageV = UIImageView()
conentImageV.image = UIImage(named: "collectionImageV")
conentImageV.contentMode = .scaleAspectFit
return conentImageV
}()
lazy var nameLabel: BorderedLabel = {
let nameLabel = BorderedLabel()
nameLabel.text = "Air Horn"
nameLabel.font = UIFont(name: "PaytoneOne-Regular", size: 20)
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.equalToSuperview()
}
conentImageV.snp.makeConstraints { make in
make.top.equalToSuperview().offset(16)
// make.left.equalToSuperview().offset(7)
// make.right.equalToSuperview().offset(7)
make.centerX.equalTo(bgImageV)
make.height.equalTo(140)
}
nameLabel.snp.makeConstraints { make in
make.top.equalTo(conentImageV.snp.bottom).offset(4)
make.width.equalToSuperview()
// make.height.equalTo(23)
}
}
var model:SoundCategory?{
didSet{
if let imageURL = URL(string: model?.categoryUrl ?? "") {
// wpImagV.sd_setImage(with: imageURL, completed: nil)
conentImageV.sd_setImage(with: imageURL, placeholderImage: UIImage(named: "collectionImageV"))
}
nameLabel.text = model?.categoryName
}
}
}
class BorderedLabel: UILabel {
override func drawText(in rect: CGRect) {
let context = UIGraphicsGetCurrentContext()
//
let originalTextColor = self.textColor
//
context?.setLineWidth(3) //
context?.setLineJoin(.round) //
context?.setTextDrawingMode(.stroke) //
self.textColor = UIColor.black //
//
super.drawText(in: rect)
//
context?.setTextDrawingMode(.fill) //
self.textColor = originalTextColor //
super.drawText(in: rect)
}
}