//
|
// HomeTopMenuView.swift
|
// XQMuse
|
//
|
// Created by 无故事王国 on 2024/8/12.
|
//
|
|
import UIKit
|
import JQTools
|
import RxSwift
|
|
enum ImageFromType {
|
case local
|
case url
|
}
|
|
struct HomeTopMenuItem{
|
var id = 0
|
var title = ""
|
var image = ""
|
var imageFrom:ImageFromType = .local
|
}
|
|
class HomeTopMenuView: UIView,JQNibView{
|
|
@IBOutlet weak var image_top: UIImageView!
|
@IBOutlet weak var menu_collectionView: UICollectionView!
|
@IBOutlet weak var menu_height: NSLayoutConstraint!
|
|
private var disposeBag = DisposeBag()
|
private var defaultItems = [HomeTopMenuItem]()
|
private var clouse:((HomeTopMenuItem)->Void)?
|
|
override func awakeFromNib() {
|
super.awakeFromNib()
|
|
menu_height.constant = 119
|
menu_collectionView.delegate = self
|
menu_collectionView.dataSource = self
|
menu_collectionView.isScrollEnabled = false
|
menu_collectionView.register(UINib(nibName: "HomeTopMenuCCell", bundle: nil), forCellWithReuseIdentifier: "_HomeTopMenuCCell")
|
|
defaultItems.append(HomeTopMenuItem(title: "睡眠疗愈", image: "icon_sleep", imageFrom: .local))
|
defaultItems.append(HomeTopMenuItem(title: "高频疗愈", image: "icon_band", imageFrom: .local))
|
defaultItems.append(HomeTopMenuItem(title: "清业疗愈", image: "icon_quiet", imageFrom: .local))
|
defaultItems.append(HomeTopMenuItem(title: "亲子疗愈", image: "icon_parent-child", imageFrom: .local))
|
menu_collectionView.reloadData()
|
}
|
|
func resetTopImage(){
|
if let imgUrl = UserDefaultSettingViewModel.getSetting()?.bgm?.imageUrl.jq_urlEncoded(){
|
image_top.sd_setImage(with: URL(string: imgUrl))
|
}
|
}
|
|
func resetItems(_ items:[HomeTopMenuItem]){
|
defaultItems.removeAll()
|
defaultItems = items
|
menu_collectionView.reloadData()
|
}
|
|
func insertOthers(_ others:[HomeTopMenuItem]){
|
defaultItems.append(contentsOf: others)
|
menu_collectionView.reloadData()
|
}
|
|
|
func clickItemAt(_ clouse: @escaping (HomeTopMenuItem)->Void){
|
self.clouse = clouse
|
}
|
}
|
|
|
extension HomeTopMenuView:UICollectionViewDelegate & UICollectionViewDataSource{
|
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
let item = defaultItems[indexPath.row]
|
clouse?(item)
|
}
|
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
return defaultItems.count
|
}
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "_HomeTopMenuCCell", for: indexPath) as! HomeTopMenuCCell
|
cell.setItem(defaultItems[indexPath.row])
|
cell.view_line.isHidden = indexPath.row == 3
|
return cell
|
}
|
}
|
|
extension HomeTopMenuView:UICollectionViewDelegateFlowLayout{
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
|
return 0
|
}
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
|
return 0
|
}
|
|
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
|
let w = JQ_ScreenW / 4.0
|
return CGSize(width: w, height: 119)
|
}
|
}
|