-
Notifications
You must be signed in to change notification settings - Fork 421
Expand file tree
/
Copy pathCellCustomizeViewController.swift
More file actions
218 lines (205 loc) · 10.9 KB
/
CellCustomizeViewController.swift
File metadata and controls
218 lines (205 loc) · 10.9 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
//
// CellCustomizeViewController.swift
// JXSegmentedView
//
// Created by jiaxin on 2018/12/29.
// Copyright © 2018 jiaxin. All rights reserved.
//
import UIKit
import JXSegmentedView
class CellCustomizeViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
tableView.rowHeight = 44
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath)
var itemTitle: String?
for subview in cell!.contentView.subviews {
if let label = subview as? UILabel {
itemTitle = label.text
break
}
}
let titles = ["猴哥", "青蛙王子", "旺财", "粉红猪", "喜羊羊", "黄焖鸡", "小马哥", "牛魔王", "大象先生", "神龙"]
let numbers = [1, 22, 333, 44444, 0, 66, 777, 0, 99999, 10]
let dotStates = [false, true, true, true, false, false, true, true, false, true]
let vc = ContentBaseViewController()
vc.title = itemTitle
switch itemTitle! {
case "颜色渐变":
//配置数据源
let dataSource = JXSegmentedTitleDataSource()
dataSource.isTitleColorGradientEnabled = true
dataSource.titleSelectedColor = UIColor.red
dataSource.titles = titles
dataSource.bgNormalColor = UIColor.green
vc.segmentedDataSource = dataSource
case "文字渐变":
//配置数据源
let dataSource = JXSegmentedTitleGradientDataSource()
dataSource.isTitleColorGradientEnabled = true
dataSource.titleSelectedColor = UIColor.red
dataSource.titles = titles
vc.segmentedDataSource = dataSource
case "大小缩放":
//配置数据源
let dataSource = JXSegmentedTitleDataSource()
dataSource.isTitleColorGradientEnabled = true
dataSource.titleSelectedColor = UIColor.red
dataSource.isTitleZoomEnabled = true
dataSource.titleSelectedZoomScale = 1.3
dataSource.titles = titles
vc.segmentedDataSource = dataSource
case "大小缩放+字体粗细":
//配置数据源
let dataSource = JXSegmentedTitleDataSource()
dataSource.isTitleColorGradientEnabled = true
dataSource.titleSelectedColor = UIColor.red
dataSource.isTitleZoomEnabled = true
dataSource.titleSelectedZoomScale = 1.3
dataSource.isTitleStrokeWidthEnabled = true
dataSource.titles = titles
vc.segmentedDataSource = dataSource
case "大小缩放+点击动画":
//配置数据源
let dataSource = JXSegmentedTitleDataSource()
dataSource.isTitleColorGradientEnabled = true
dataSource.titleSelectedColor = UIColor.red
dataSource.isTitleZoomEnabled = true
dataSource.titleSelectedZoomScale = 1.3
dataSource.isTitleStrokeWidthEnabled = true
dataSource.isSelectedAnimable = true
dataSource.titles = titles
let indicator = JXSegmentedIndicatorLineView()
indicator.indicatorWidth = JXSegmentedViewAutomaticDimension
vc.segmentedView.indicators = [indicator]
vc.segmentedDataSource = dataSource
case "大小缩放+Cell宽度缩放":
//高仿汽车之家
//配置数据源
let dataSource = JXSegmentedTitleDataSource()
dataSource.isTitleColorGradientEnabled = true
dataSource.titleSelectedColor = UIColor.red
dataSource.isTitleZoomEnabled = true
dataSource.titleSelectedZoomScale = 1.3
dataSource.isTitleStrokeWidthEnabled = true
dataSource.isSelectedAnimable = true
dataSource.isItemWidthZoomEnabled = true
dataSource.titles = titles
let indicator = JXSegmentedIndicatorLineView()
indicator.indicatorWidth = JXSegmentedViewAutomaticDimension
vc.segmentedView.indicators = [indicator]
vc.segmentedDataSource = dataSource
case "数字":
//配置数据源
let dataSource = JXSegmentedNumberDataSource()
dataSource.isTitleColorGradientEnabled = true
dataSource.titles = titles
dataSource.numbers = numbers
// dataSource.numberHeight = 20
// dataSource.numberFont = .systemFont(ofSize: 15)
dataSource.numberStringFormatterClosure = {(number) -> String in
if number > 999 {
return "999+"
}
return "\(number)"
}
vc.segmentedDataSource = dataSource
case "红点":
//配置数据源
let dataSource = JXSegmentedDotDataSource()
dataSource.isTitleColorGradientEnabled = true
dataSource.titles = titles
dataSource.dotStates = dotStates
vc.segmentedDataSource = dataSource
case "文字和图片":
//配置数据源
let dataSource = JXSegmentedTitleImageDataSource()
dataSource.isTitleColorGradientEnabled = true
dataSource.titles = titles
dataSource.titleImageType = .rightImage
dataSource.isImageZoomEnabled = true
dataSource.normalImageInfos = ["monkey", "frog", "dog", "pig", "sheep", "chicken", "horse", "cow", "elephant", "dragon"]
dataSource.loadImageClosure = {(imageView, normalImageInfo) in
//如果normalImageInfo传递的是图片的地址,你需要借助SDWebImage等第三方库进行图片加载。
//加载bundle内的图片,就用下面的方式,内部默认也采用该方法。
imageView.image = UIImage(named: normalImageInfo)
}
vc.segmentedDataSource = dataSource
case "文字或者图片":
//配置数据源
let dataSource = JXSegmentedTitleOrImageDataSource()
dataSource.isTitleColorGradientEnabled = true
dataSource.titleSelectedColor = UIColor.red
dataSource.isTitleZoomEnabled = true
dataSource.titleSelectedZoomScale = 1.3
dataSource.isTitleStrokeWidthEnabled = true
dataSource.isItemTransitionEnabled = false
dataSource.isSelectedAnimable = true
dataSource.titles = titles
dataSource.selectedImageInfos = ["monkey", nil, "dog", nil, "sheep", "chicken", "horse", nil, nil, "dragon"]
dataSource.loadImageClosure = {(imageView, normalImageInfo) in
//如果normalImageInfo传递的是图片的地址,你需要借助SDWebImage等第三方库进行图片加载。
//加载bundle内的图片,就用下面的方式,内部默认也采用该方法。
imageView.image = UIImage(named: normalImageInfo)
}
vc.segmentedDataSource = dataSource
case "多行文字(自己添加换行符)":
//配置数据源
let dataSource = JXSegmentedTitleDataSource()
dataSource.isTitleColorGradientEnabled = true
dataSource.titleSelectedColor = UIColor.red
dataSource.titleNumberOfLines = 2
dataSource.titles = ["猴哥\nmonkey", "青蛙王子\nfrog", "旺财\ndot", "粉红猪\npig", "喜羊羊\nsheep", "黄焖鸡\nchicken", "小马哥\nhorse", "牛魔王\ncow", "大象先生\nelepant", "神龙\ndragon"]
vc.segmentedDataSource = dataSource
case "多行文字(固定宽度自动换行)":
//配置数据源
let dataSource = JXSegmentedTitleDataSource()
dataSource.isTitleColorGradientEnabled = true
dataSource.titleSelectedColor = UIColor.red
dataSource.titleNumberOfLines = 2
dataSource.itemWidth = 60
dataSource.titles = ["猴哥 monkey", "青蛙王子 frog", "旺财 dot", "粉红猪 pig", "喜羊羊 sheep", "黄焖鸡 chicken", "小马哥 horse", "牛魔王 cow", "大象先生 elepant", "神龙 dragon"]
vc.segmentedDataSource = dataSource
case "多行富文本":
//配置数据源
let dataSource = JXSegmentedTitleAttributeDataSource()
func formatNormal(attriText: NSMutableAttributedString) {
attriText.addAttributes([NSAttributedString.Key.foregroundColor : UIColor.blue, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 15)], range: NSRange(location: 0, length: 2))
attriText.addAttributes([NSAttributedString.Key.foregroundColor : UIColor.black, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 13)], range: NSRange(location: 2, length: attriText.string.count - 2))
}
func formatSelected(attriText: NSMutableAttributedString) {
attriText.addAttributes([NSAttributedString.Key.foregroundColor : UIColor.red, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 16)], range: NSRange(location: 0, length: 2))
attriText.addAttributes([NSAttributedString.Key.foregroundColor : UIColor.black, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 14)], range: NSRange(location: 2, length: attriText.string.count - 2))
}
let mondayAttriText = NSMutableAttributedString(string: "周一\n1月7号")
formatNormal(attriText: mondayAttriText)
let tuesdayAttriText = NSMutableAttributedString(string: "周二\n1月8号")
formatNormal(attriText: tuesdayAttriText)
let wednesdayAttriText = NSMutableAttributedString(string: "周三\n1月9号")
formatNormal(attriText: wednesdayAttriText)
dataSource.attributedTitles = [mondayAttriText.copy(), tuesdayAttriText.copy(), wednesdayAttriText.copy()] as! [NSAttributedString]
formatSelected(attriText: mondayAttriText)
formatSelected(attriText: tuesdayAttriText)
formatSelected(attriText: wednesdayAttriText)
dataSource.selectedAttributedTitles = [mondayAttriText.copy(), tuesdayAttriText.copy(), wednesdayAttriText.copy()] as? [NSAttributedString]
vc.segmentedDataSource = dataSource
//配置指示器
let indicator = JXSegmentedIndicatorBackgroundView()
indicator.indicatorHeight = 40
indicator.indicatorCornerRadius = 5
vc.segmentedView.indicators = [indicator]
case "多种cell":
let dataSource = JXSegmentedMixcellDataSource()
vc.segmentedDataSource = dataSource
case "Title Configuration":
let vc = TitleConfigurationViewController()
navigationController?.pushViewController(vc, animated: true)
return
default:
break
}
navigationController?.pushViewController(vc, animated: true)
}
}