forked from MxABC/swiftScan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyCodeViewController.swift
108 lines (73 loc) · 3.17 KB
/
MyCodeViewController.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
//
// MyCodeViewController.swift
// swiftScan
//
// Created by xialibing on 15/12/10.
// Copyright © 2015年 xialibing. All rights reserved.
//
import UIKit
class MyCodeViewController: UIViewController {
//二维码
var qrView = UIView()
var qrImgView = UIImageView()
//条形码
var tView = UIView()
var tImgView = UIImageView()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.view.backgroundColor = UIColor.white
drawCodeShowView()
createQR1()
createCode128()
}
//MARK: ------二维码、条形码显示位置
func drawCodeShowView()
{
//二维码
let rect = CGRect(x: (self.view.frame.width-self.view.frame.width*5/6)/2, y: 100, width: self.view.frame.width*5/6, height: self.view.frame.width*5/6)
qrView.frame = rect
self.view.addSubview(qrView)
qrView.backgroundColor = UIColor.white
qrView.layer.shadowOffset = CGSize(width: 0, height: 2);
qrView.layer.shadowRadius = 2;
qrView.layer.shadowColor = UIColor.black.cgColor
qrView.layer.shadowOpacity = 0.5;
qrImgView.bounds = CGRect(x: 0, y: 0, width: qrView.frame.width-12, height: qrView.frame.width-12)
qrImgView.center = CGPoint(x: qrView.frame.width/2, y: qrView.frame.height/2);
qrView .addSubview(qrImgView)
//条形码
tView.frame = CGRect(x: (self.view.frame.width-self.view.frame.width*5/6)/2,
y: rect.maxY+20,
width: self.view.frame.width*5/6,
height: self.view.frame.width*5/6*0.5)
self.view .addSubview(tView)
tView.layer.shadowOffset = CGSize(width: 0, height: 2);
tView.layer.shadowRadius = 2;
tView.layer.shadowColor = UIColor.black.cgColor
tView.layer.shadowOpacity = 0.5;
tImgView.bounds = CGRect(x: 0, y: 0, width: tView.frame.width-12, height: tView.frame.height-12);
tImgView.center = CGPoint(x: tView.frame.width/2, y: tView.frame.height/2);
tView .addSubview(tImgView)
}
func createQR1()
{
// qrView.hidden = false
// tView.hidden = true
let qrImg = LBXScanWrapper.createCode(codeType: "CIQRCodeGenerator",codeString:"[email protected]", size: qrImgView.bounds.size, qrColor: UIColor.black, bkColor: UIColor.white)
let logoImg = UIImage(named: "logo.JPG")
qrImgView.image = LBXScanWrapper.addImageLogo(srcImg: qrImg!, logoImg: logoImg!, logoSize: CGSize(width: 30, height: 30))
}
func createCode128()
{
let qrImg = LBXScanWrapper.createCode128(codeString: "005103906002", size: qrImgView.bounds.size, qrColor: UIColor.black, bkColor: UIColor.white)
tImgView.image = qrImg
}
deinit
{
print("MyCodeViewController deinit")
}
}