-
Notifications
You must be signed in to change notification settings - Fork 64
/
FWDemoViewController.swift
140 lines (116 loc) · 5.93 KB
/
FWDemoViewController.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
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
//
// FWDemoViewController.swift
// FWPopupView
//
// Created by xfg on 2018/3/26.
// Copyright © 2018年 xfg. All rights reserved.
//
import Foundation
import UIKit
class FWDemoViewController: UITableViewController {
var titleArray = ["Alert - 单个按钮", "Alert - 两个按钮", "Alert - 多个按钮", "Alert - 带输入框", "Alert - 带自定义视图", "Sheet - 少量Item", "Sheet - 大量Item", "Custom - 自定义弹窗"]
let block: FWPopupItemHandler = { (index) in
print("AlertView:点击了第\(index)个按钮")
}
let completeBlock: FWPopupCompletionBlock = { (popupView, isCompletion) in
print(popupView)
}
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.title = "FWPopupView"
self.tableView.estimatedRowHeight = 44.0
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cellId")
// 设置弹窗外部可点击(当且仅当attachedView = FWPopupWindow.sharedInstance.attachView()时有效)
// FWPopupWindow.sharedInstance.touchWildToHide = true
}
}
extension FWDemoViewController {
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return titleArray.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: .default, reuseIdentifier: "cellId")
cell.textLabel?.text = titleArray[indexPath.row]
cell.textLabel?.numberOfLines = 0
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch indexPath.row {
case 0:
let alertView = FWAlertView.alert(title: "标题", detail: "描述描述描述描述") { (index) in
print("点击了确定")
}
alertView.show()
break
case 1:
let alertView = FWAlertView.alert(title: "标题", detail: "描述描述描述描述描述描述描述描述描述描述", confirmBlock: { (index) in
print("点击了确定")
}, cancelBlock: { (index) in
print("点击了取消")
})
// 设置AlertView外部背景色
alertView.attachedView?.fwBackgroundViewColor = UIColor(white: 0, alpha: 0.4)
alertView.show(completionBlock: { (popupView, isCompletion) in
})
break
case 2:
let items = [FWPopupItem(title: "取消", itemType: .normal, isCancel: true, handler: block),
FWPopupItem(title: "确定", itemType: .normal, isCancel: false, handler: block),
FWPopupItem(title: "其他", itemType: .normal, isCancel: false, handler: block)]
let vProperty = FWAlertViewProperty()
vProperty.detailColor = UIColor.red
let alertView = FWAlertView.alert(title: "标题", detail: "描述描述描述描述描述描述描述描述描述描述", inputPlaceholder: nil, keyboardType: .default, customView: nil, items: items, vProperty: vProperty)
alertView.show()
break
case 3:
let items = [FWPopupItem(title: "取消", itemType: .normal, isCancel: true, handler: block),
FWPopupItem(title: "确定", itemType: .normal, isCancel: false, handler: block)]
let alertView = FWAlertView.alert(title: "标题", detail: "带输入框", inputPlaceholder: "请输入...", keyboardType: .default, customView: nil, items: items)
print("点击了确定")
alertView.show(completionBlock: { (popupView, isCompletion) in
print("点击了取消")
})
break
case 4:
let items = [FWPopupItem(title: "取消", itemType: .normal, isCancel: true, handler: block),
FWPopupItem(title: "确定", itemType: .normal, isCancel: false, handler: block)]
// 注意:添加自定义的视图,需要设置确定的Frame值
let customImageView = UIImageView(image: UIImage(named: "audio_bgm_4"))
let alertView = FWAlertView.alert(title: "标题", detail: "带自定义视图", inputPlaceholder: nil, keyboardType: .default, customView: customImageView, items: items)
print("点击了确定")
alertView.show(completionBlock: { (popupView, isCompletion) in
print("点击了取消")
})
break
case 5:
let items = ["Sheet0", "Sheet1", "Sheet2", "Sheet3"]
let sheetView = FWSheetView.sheet(title: "标题", itemTitles: items, itemBlock: { (index) in
print("Sheet:点击了第\(index)个按钮")
}, cancenlBlock: {
print("点击了取消")
})
sheetView.show()
break
case 6:
let items = ["Sheet0", "Sheet1", "Sheet2", "Sheet3", "Sheet4", "Sheet5", "Sheet6", "Sheet7", "Sheet8", "Sheet9", "Sheet10", "Sheet11", "Sheet12", "Sheet13", "Sheet14"]
let sheetView = FWSheetView.sheet(title: "标题", itemTitles: items, itemBlock: { (index) in
print("Sheet:点击了第\(index)个按钮")
}, cancenlBlock: {
print("点击了取消")
})
sheetView.show()
break
case 7:
let dateView = FWDateView.date(confirmBlock: { (datePicker) in
print("点击了 FWDateView 的确定")
}, cancelBlock: {
print("点击了 FWDateView 的取消")
})
dateView.show()
break
default:
break
}
}
}