-
Notifications
You must be signed in to change notification settings - Fork 369
/
NestViewController.swift
78 lines (64 loc) · 2.68 KB
/
NestViewController.swift
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
//
// NestViewController.swift
// JXSegmentedView
//
// Created by jiaxin on 2019/1/3.
// Copyright © 2019 jiaxin. All rights reserved.
//
import UIKit
import JXSegmentedView
class NestViewController: UIViewController {
let segmentedDataSource = JXSegmentedTitleDataSource()
let segmentedView = JXSegmentedView()
lazy var listContainerView: JXSegmentedListContainerView! = {
return JXSegmentedListContainerView(dataSource: self)
}()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
let totalItemWidth: CGFloat = 150
let titles = ["吃饭🍚", "运动💪"]
//segmentedViewDataSource一定要通过属性强持有!!!!!!!!!
segmentedDataSource.itemWidth = totalItemWidth/CGFloat(titles.count)
segmentedDataSource.titles = titles
segmentedDataSource.isTitleMaskEnabled = true
segmentedDataSource.titleNormalColor = UIColor.red
segmentedDataSource.titleSelectedColor = UIColor.white
segmentedDataSource.itemSpacing = 0
let indicator = JXSegmentedIndicatorBackgroundView()
indicator.indicatorHeight = 30
indicator.indicatorWidthIncrement = 0
indicator.indicatorColor = UIColor.red
segmentedView.frame = CGRect(x: 0, y: 0, width: totalItemWidth, height: 30)
segmentedView.layer.masksToBounds = true
segmentedView.layer.cornerRadius = 15
segmentedView.layer.borderColor = UIColor.red.cgColor
segmentedView.layer.borderWidth = 1/UIScreen.main.scale
segmentedView.dataSource = segmentedDataSource
segmentedView.indicators = [indicator]
navigationItem.titleView = segmentedView
segmentedView.listContainer = listContainerView
view.addSubview(listContainerView)
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
listContainerView.frame = view.bounds
}
}
extension NestViewController: JXSegmentedListContainerViewDataSource {
func numberOfLists(in listContainerView: JXSegmentedListContainerView) -> Int {
if let titleDataSource = segmentedView.dataSource as? JXSegmentedBaseDataSource {
return titleDataSource.dataSource.count
}
return 0
}
func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
let vc = NestChildViewController()
if index == 0 {
vc.titles = ["吃鸡🍗", "吃西瓜🍉", "吃热狗🌭"]
}else if index == 1 {
vc.titles = ["高尔夫🏌", "滑雪⛷", "自行车🚴"]
}
return vc
}
}