//
|
// HomeVC.swift
|
// XQMuse
|
//
|
// Created by 无故事王国 on 2024/8/12.
|
//
|
|
import UIKit
|
import JQTools
|
|
struct TitleItem{
|
var title = ""
|
var subTitle = ""
|
var hasMore:Bool = false
|
}
|
|
class HomeVC: BaseVC {
|
private var tableView:UITableView!
|
private let topMenuView = HomeTopMenuView.jq_loadNibView()
|
private var titleItems = [TitleItem]()
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
|
titleItems.append(TitleItem(title: "每日疗愈", subTitle: "Daily Meditation"))
|
titleItems.append(TitleItem(title: "私人订制", subTitle: "Private Meditation",hasMore: true))
|
titleItems.append(TitleItem(title: "新手冥想指南", subTitle: "Meditation guide"))
|
titleItems.append(TitleItem(title: "放松助眠", subTitle: "与内心的宁静与喜悦入睡",hasMore:true))
|
titleItems.append(TitleItem(title: "放松助眠", subTitle: "与内心的宁静与喜悦入睡",hasMore:true))
|
|
}
|
|
override func setUI() {
|
super.setUI()
|
|
let titleView = UIView()
|
titleView.frame = CGRect(x: 0, y: 0, width: 100, height: 40)
|
let titleL = UILabel()
|
titleL.font = Def_SourceHanSansCN_Regular(fontSize: 21)
|
titleL.text = "心 泉 疗 愈"
|
titleL.textAlignment = .center
|
titleL.textColor = UIColor(hexStr: "#252A23")
|
titleL.frame = CGRect(x: 0, y: 0, width: 100, height: 19)
|
|
let subTitleL = UILabel()
|
subTitleL.font = Def_Agenda_Light(fontSize: 8)
|
subTitleL.text = "XIN QUAN"
|
subTitleL.textAlignment = .center
|
subTitleL.textColor = UIColor(hexStr: "#252A23")
|
subTitleL.frame = CGRect(x: 0, y: 20, width: 100, height: 19)
|
|
|
titleView.addSubview(titleL)
|
titleView.addSubview(subTitleL)
|
|
|
navigationItem.titleView = titleView
|
|
let search = UIButton(type: .custom)
|
search.setImage(UIImage(named: "btn_search"), for: .normal)
|
search.addTarget(self, action: #selector(searchAction), for: .touchUpInside)
|
search.bounds = CGRect(origin: .zero, size:CGSize(width: 50, height: 30))
|
navigationItem.leftBarButtonItem = UIBarButtonItem(customView: search)
|
|
|
let voices = UIButton(type: .custom)
|
voices.setImage(UIImage(named: "btn_voices"), for: .normal)
|
voices.addTarget(self, action: #selector(settingvoiceAction), for: .touchUpInside)
|
voices.bounds = CGRect(origin: .zero, size:CGSize(width: 50, height: 30))
|
navigationItem.rightBarButtonItem = UIBarButtonItem(customView: voices)
|
|
tableView = UITableView(frame: .zero, style: .plain)
|
tableView.showsVerticalScrollIndicator = false
|
DispatchQueue.main.async {
|
let height = self.topMenuView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).height
|
self.topMenuView.frame = CGRect(x: 0, y: 0, width: JQ_ScreenW, height: height - 70)
|
self.tableView.tableHeaderView = self.topMenuView
|
}
|
|
tableView.tableHeaderView = topMenuView
|
|
tableView.register(UINib(nibName: "Home_Style_1_TCell", bundle: nil), forCellReuseIdentifier: "_Home_Style_1_TCell")
|
tableView.register(UINib(nibName: "Home_Style_2_TCell", bundle: nil), forCellReuseIdentifier: "_Home_Style_2_TCell")
|
tableView.register(UINib(nibName: "Home_Style_3_TCell", bundle: nil), forCellReuseIdentifier: "_Home_Style_3_TCell")
|
tableView.register(UINib(nibName: "Home_Style_4_TCell", bundle: nil), forCellReuseIdentifier: "_Home_Style_4_TCell")
|
|
tableView.separatorStyle = .none
|
tableView.delegate = self
|
tableView.dataSource = self
|
if #available(iOS 15.0, *) {
|
tableView.sectionHeaderTopPadding = 0
|
} else {
|
|
}
|
tableView.register(HomeHeaderView.self, forHeaderFooterViewReuseIdentifier: "_HomeHeaderView")
|
view.addSubview(tableView)
|
tableView.snp.makeConstraints { make in
|
make.edges.equalToSuperview()
|
}
|
}
|
|
override func setRx() {
|
topMenuView.clickItemAt {[unowned self] item in
|
let vc = HomeItemListVC(topTitle: item.title, id: item.id)
|
self.push(vc: vc)
|
}
|
}
|
|
@objc func searchAction(){
|
let vc = SearchVC()
|
push(vc: vc)
|
}
|
|
@objc func settingvoiceAction(){
|
let vc = BackgroundVoiceVC()
|
push(vc: vc)
|
|
// let nav = LoginNav(rootViewController: LoginVC())
|
// nav.modalPresentationStyle = .fullScreen
|
// present(nav, animated: true)
|
}
|
|
}
|
|
extension HomeVC:UITableViewDelegate & UITableViewDataSource{
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
if indexPath.section == 0{
|
let cell = tableView.dequeueReusableCell(withIdentifier: "_Home_Style_1_TCell") as! Home_Style_1_TCell
|
return cell
|
}
|
|
if indexPath.section == 1{
|
let cell = tableView.dequeueReusableCell(withIdentifier: "_Home_Style_2_TCell") as! Home_Style_2_TCell
|
return cell
|
}
|
|
if indexPath.section == 2{
|
let cell = tableView.dequeueReusableCell(withIdentifier: "_Home_Style_2_TCell") as! Home_Style_2_TCell
|
cell.view_shadow.isHidden = true
|
return cell
|
}
|
|
if indexPath.section == 3{
|
let cell = tableView.dequeueReusableCell(withIdentifier: "_Home_Style_3_TCell") as! Home_Style_3_TCell
|
return cell
|
}
|
|
if indexPath.section == 4{
|
let cell = tableView.dequeueReusableCell(withIdentifier: "_Home_Style_4_TCell") as! Home_Style_4_TCell
|
return cell
|
}
|
|
if indexPath.section == 5{
|
let cell = tableView.dequeueReusableCell(withIdentifier: "_Home_Style_4_TCell") as! Home_Style_4_TCell
|
return cell
|
}
|
|
return UITableViewCell()
|
}
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
return 1
|
}
|
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
if indexPath.section == 0 || indexPath.section == 1 || indexPath.section == 2{
|
return JQ_ScreenW * 0.551
|
}
|
if indexPath.section == 3{
|
return 397.3
|
}
|
if indexPath.section == 4 || indexPath.section == 5{
|
return 328
|
}
|
return 0
|
}
|
|
func numberOfSections(in tableView: UITableView) -> Int {
|
return titleItems.count
|
}
|
|
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
return 80.5
|
}
|
|
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "_HomeHeaderView") as! HomeHeaderView
|
headerView.setTitle(titleItems[section].title, subTitle: titleItems[section].subTitle)
|
headerView.btn_more.isHidden = !titleItems[section].hasMore
|
|
if section == 1{
|
headerView.btn_more.setImage(UIImage(named: "btn_more"), for: .normal)
|
}else{
|
headerView.btn_more.setImage(UIImage(named: "icon_exchange"), for: .normal)
|
}
|
|
return headerView
|
}
|
|
|
}
|