-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathViewController.swift
More file actions
97 lines (74 loc) · 2.6 KB
/
Copy pathViewController.swift
File metadata and controls
97 lines (74 loc) · 2.6 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
//
// ViewController.swift
// ScanCodeDemo
//
// Created by YTiOSer on 18/5.
// Copyright © 2018 YTiOSer. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
fileprivate var label_Type: UILabel! //类型
fileprivate var label_Content: UILabel! //扫码结果
override func viewDidLoad() {
super.viewDidLoad()
initMainView()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
extension ViewController{
@objc func codeScan() {
let controller = YTScanCodeViewController()
present(controller, animated: true, completion: nil)
controller.setBackClosure { [unowned self] (type, code) -> Void in
self.label_Content.text = "code: \(code)"
if type == "vin"{
self.label_Type.text = "类型: VIN"
}else if type == "oem"{
self.label_Type.text = "类型: 二维码"
}
}
}
}
// MARK: UI
extension ViewController{
func initMainView() {
let btn = UIButton.init(type: .custom)
btn.setTitle("扫码", for: .normal)
btn.setTitleColor(UIColor.orange, for: .normal)
btn.titleLabel?.font = UIFont.systemFont(ofSize: 18)
btn.layer.borderWidth = 1
btn.layer.borderColor = UIColor.orange.cgColor
btn.addTarget(self, action: #selector(codeScan), for: .touchUpInside)
view.addSubview(btn)
btn.snp.makeConstraints { (make) in
make.left.equalTo(13)
make.right.equalTo(-13)
make.top.equalTo(200)
make.height.equalTo(50)
}
label_Type = createCustomLabel(content: "类型: ")
view.addSubview(label_Type)
label_Type.snp.makeConstraints { (make) in
make.left.right.equalTo(btn)
make.top.equalTo(btn.snp.bottom).offset(50)
make.height.equalTo(25)
}
label_Content = createCustomLabel(content: "code: ")
view.addSubview(label_Content)
label_Content.snp.makeConstraints { (make) in
make.left.right.height.equalTo(label_Type)
make.top.equalTo(label_Type.snp.bottom).offset(20)
}
}
func createCustomLabel(content: String) -> UILabel {
let label = UILabel()
label.text = content
label.textColor = UIColor.gray
label.font = UIFont.systemFont(ofSize: 15)
label.sizeToFit()
return label
}
}