5
5
# CarBode
6
6
## Free and Opensource Barcode scanner & ; Barcode generator for swiftUI
7
7
8
+ ![ CarBodeDemo] ( https://raw.githubusercontent.com/heart/CarBode-Barcode-Scanner-For-SwiftUI/master/logo/demo.gif )
9
+
8
10
# Why you must use CarBode
9
11
1 . CarBode have both Barcode Scanner and Barcode Generator
10
12
1 . CarBode is a lightweight components
18
20
- [ Example project] ( #example-project )
19
21
- [ How to use scanner view] ( #how-to-use-scanner-view )
20
22
- [ Add camera usage description to ` info.plist ` ] ( #add-camera-usage-description-to-your-infoplist )
23
+ - [ Simple Sscanner] ( #simple-scanner )
24
+ - [ Draw box around the barcode] ( #draw-box-around-the-barcode )
21
25
- [ torch light on/off] ( #how-to-turn-torch-light-onoff )
22
- - [ Test on iOS simulator] ( #test-on-ios-simulator )
23
- - [ Barcode types support] ( #barcode-types-support )
24
26
- [ Switch front/back camera] ( #switch-to-front-camera )
27
+ - [ Barcode types support] ( #barcode-types-support )
28
+ - [ Test on iOS simulator] ( #test-on-ios-simulator )
25
29
- [ How to use barcode generator view] ( #how-to-use-barcode-generator-view )
26
30
- [ Barcode type you can generate] ( #barcode-type-you-can-generate )
27
31
- [ Rotate your barcode] ( #rotate-your-barcode )
@@ -35,7 +39,7 @@ The preferred way of installing SwiftUIX is via the [Swift Package Manager](http
35
39
36
40
1 . In Xcode, open your project and navigate to ** File** → ** Swift Packages** → ** Add Package Dependency...**
37
41
2 . Paste the repository URL (` https://github.com/heart/CarBode-Barcode-Scanner-For-SwiftUI ` ) and click ** Next** .
38
- 3 . For ** Rules** , select ** Branch** (with branch set to ` 2.0.1 ` ).
42
+ 3 . For ** Rules** , select ** Branch** (with branch set to ` 2.1.0 ` ).
39
43
4 . Click ** Finish** .
40
44
41
45
# Example project
@@ -53,6 +57,7 @@ CarBode-Barcode-Scanner-For-SwiftUI/ExampleProject/ExampleProject.xcodeproj
53
57
<string >This app needs access to the camera, to be able to read barcodes.</string >
54
58
```
55
59
60
+ # Simple Scanner
56
61
``` Swift
57
62
import SwiftUI
58
63
import CarBode
@@ -76,6 +81,44 @@ struct ContentView: View {
76
81
}
77
82
```
78
83
84
+ # Draw box around the barcode
85
+ ```Swift
86
+ import SwiftUI
87
+ import CarBode
88
+ import AVFoundation // import to access barcode types you want to scan
89
+
90
+ struct ContentView : View {
91
+ var body: some View {
92
+ VStack {
93
+ CBScanner (
94
+ supportBarcode : .constant ([.qr , .code128 ]), // Set type of barcode you want to scan
95
+ scanInterval : .constant (5.0 ) // Event will trigger every 5 seconds
96
+ ){
97
+ // When the scanner found a barcode
98
+ print ($0 .value )
99
+ print (" Barcode Type is" , $0 .type .rawValue )
100
+ }
101
+ onDraw : {
102
+ print (" Preview View Size = \( $0 .cameraPreviewView .bounds ) " )
103
+ print (" Barcode Corners = \( $0 .corners ) " )
104
+
105
+ // line width
106
+ let lineWidth = 2
107
+
108
+ // line color
109
+ let lineColor = UIColor.red
110
+
111
+ // Fill color with opacity
112
+ // You also can use UIColor.clear if you don't want to draw fill color
113
+ let fillColor = UIColor (red : 0 , green : 1 , blue : 0.2 , alpha : 0.4 )
114
+
115
+ // Draw box
116
+ $0 .draw (lineWidth : lineWidth, lineColor : lineColor, fillColor : fillColor)
117
+ }
118
+ }
119
+ }
120
+ ```
121
+
79
122
# How to turn torch light on/ off
80
123
```Swift
81
124
import SwiftUI
@@ -242,6 +285,8 @@ CBBarcodeView(data: ..... ,
242
285
CarBode welcomes contributions in the form of GitHub issues and pull- requests.
243
286
244
287
## Changelog
288
+ - 2.1.0 You can draw a box around the barcode
289
+ - 2.0.1 Fixed bugs
245
290
- 2.0.0 I learned many more things about SwiftUI then I decide to restructure the scanner I hope you will like it. And this version you can switch front and back camera.
246
291
- 1.5.0 Fixed bugs and you can read the barcode type when scanner found it
247
292
- 1.4.0 Rename component and add new barcode generator view component
0 commit comments