//
|
// HomeListenVC.swift
|
// DolphinEnglishLearnStudent
|
//
|
// Created by 无故事王国 on 2024/5/23.
|
//
|
|
import UIKit
|
import SPPageMenu
|
import FFPage
|
|
class HomeListenVC: BaseVC {
|
|
//限制后面的点击:天数(1开始)
|
private var limitDay = 7
|
|
private lazy var menu:SPPageMenu = {
|
let menu = SPPageMenu(frame: .zero, trackerStyle: .line)
|
menu.itemTitleFont = UIFont(name: "Impact", size: 18) ?? .systemFont(ofSize: 18, weight: .medium)
|
menu.setItems(["Day1","Day2","Day3","Day4","Day5","自主游戏","听故事"], selectedItemIndex: 0)
|
menu.selectedItemTitleColor = UIColor(hexStr: "#41A2EB")
|
menu.unSelectedItemTitleColor = UIColor.black.withAlphaComponent(0.71)
|
menu.trackerWidth = 22
|
menu.setTrackerHeight(6, cornerRadius: 3)
|
menu.trackerFollowingMode = .half
|
menu.tracker.image = UIImage.jq_image(with: UIColor(hexStr: "#41A2EB"), size: CGSize(width: 1, height: 1), alpha: 1)
|
menu.permutationWay = .notScrollAdaptContent
|
menu.dividingLineHeight = 0.001
|
return menu
|
}()
|
|
private lazy var pageVC:FFPageViewController = {
|
let vc = FFPageViewController()
|
vc.scrollview.isScrollEnabled = false
|
return vc
|
}()
|
|
override func viewDidLoad() {
|
super.viewDidLoad()
|
}
|
|
override func setUI() {
|
super.setUI()
|
|
let topMenuView = UIView()
|
topMenuView.backgroundColor = .white
|
topMenuView.jq_cornerRadius = 8
|
view.addSubview(topMenuView)
|
topMenuView.snp.makeConstraints { make in
|
make.top.equalTo(self.view.safeAreaLayoutGuide).offset(9)
|
make.left.equalTo(234)
|
make.right.equalTo(-234)
|
make.height.equalTo(59)
|
}
|
|
menu.delegate = self
|
topMenuView.addSubview(menu)
|
menu.snp.makeConstraints { make in
|
make.left.right.equalToSuperview()
|
make.centerY.equalToSuperview()
|
make.height.equalTo(32)
|
}
|
|
|
pageVC.delegate = self
|
view.addSubview(pageVC.view)
|
pageVC.view.snp.makeConstraints { make in
|
make.top.equalTo(menu.snp.bottom).offset(19)
|
make.left.equalTo(topMenuView.snp.left)
|
make.right.equalTo(topMenuView.snp.right)
|
make.bottom.equalTo(self.view.safeAreaLayoutGuide.snp.bottom)
|
}
|
|
for (index,titleL) in (menu.subviews.last?.subviews[1].subviews ?? []).filter({$0 is UIButton}).enumerated(){
|
if index >= limitDay{
|
if let btn = titleL as? UIButton{
|
btn.setTitleColor(.black.withAlphaComponent(0.33), for: .normal)
|
menu.setEnabled(false, forItemAt: UInt(index))
|
}
|
}
|
}
|
}
|
}
|
|
extension HomeListenVC:SPPageMenuDelegate{
|
func pageMenu(_ pageMenu: SPPageMenu, itemSelectedAt index: Int) {
|
pageVC.scroll(toPage: index, animation: true)
|
}
|
}
|
|
extension HomeListenVC:FFPageViewControllerDelegate{
|
func totalPagesOfpageViewController(_ pageViewConteoller: FFPageViewController) -> UInt {
|
return menu.numberOfItems
|
}
|
|
func pageViewController(_ pageViewController: FFPageViewController, currentPageChanged currentPage: Int) {
|
menu.selectedItemIndex = currentPage
|
}
|
|
func pageViewController(_ pageViewConteoller: FFPageViewController, controllerForPage page: Int) -> UIViewController {
|
return HomeListenSubVC(page: page)
|
}
|
}
|