add
无故事王国
2024-05-28 64d4343b54e747804656a3fb7eca4a2d14d6e5de
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//
//  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)
                }
}