Toggle navigation
Toggle navigation
This project
Loading...
Sign in
open-source
/
warply_sdk_framework
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
Manos Chorianopoulos
2022-04-28 19:02:03 +0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
b19102aba75bac6fc23a0ec892c0f63cc6925fbb
b19102ab
1 parent
d86a71ce
barcode lib v17
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
3 deletions
WarplySDKFrameworkIOS/WarplySDKFrameworkIOS.xcworkspace/xcuserdata/manos.xcuserdatad/UserInterfaceState.xcuserstate
WarplySDKFrameworkIOS/WarplySDKFrameworkIOS/CouponBarcodeView.swift
WarplySDKFrameworkIOS/WarplySDKFrameworkIOS.xcworkspace/xcuserdata/manos.xcuserdatad/UserInterfaceState.xcuserstate
View file @
b19102a
No preview for this file type
WarplySDKFrameworkIOS/WarplySDKFrameworkIOS/CouponBarcodeView.swift
View file @
b19102a
...
...
@@ -14,6 +14,33 @@ import RSBarcodes_Swift
import
AVFoundation
extension
String
{
var
length
:
Int
{
return
count
}
subscript
(
i
:
Int
)
->
String
{
return
self
[
i
..<
i
+
1
]
}
func
substring
(
fromIndex
:
Int
)
->
String
{
return
self
[
min
(
fromIndex
,
length
)
..<
length
]
}
func
substring
(
toIndex
:
Int
)
->
String
{
return
self
[
0
..<
max
(
0
,
toIndex
)]
}
subscript
(
r
:
Range
<
Int
>
)
->
String
{
let
range
=
Range
(
uncheckedBounds
:
(
lower
:
max
(
0
,
min
(
length
,
r
.
lowerBound
)),
upper
:
min
(
length
,
max
(
0
,
r
.
upperBound
))))
let
start
=
index
(
startIndex
,
offsetBy
:
range
.
lowerBound
)
let
end
=
index
(
start
,
offsetBy
:
range
.
upperBound
-
range
.
lowerBound
)
return
String
(
self
[
start
..<
end
])
}
}
extension
CouponBarcodeView
{
struct
headerView
:
View
{
var
goBack
:
()
->
()
...
...
@@ -95,8 +122,44 @@ extension CouponBarcodeView {
return
nil
}
func
constructBarcode
()
->
String
?
{
// EAN 13 barcode construction
// let couponData = coupon["coupon_data"] as? [String: Any] ?? ["":""]
let
couponString
=
coupon
[
"coupon"
]
as?
String
??
""
if
(
!
couponString
.
isEmpty
)
{
var
checkDigit
=
0
;
var
result
=
0
;
var
fixedCouponCode
=
couponString
;
if
(
fixedCouponCode
.
count
<
12
)
{
let
loops
=
12
-
fixedCouponCode
.
count
;
var
zerosStr
=
""
;
for
i
in
0
..<
loops
{
zerosStr
+=
"0"
}
fixedCouponCode
=
zerosStr
+
fixedCouponCode
;
}
var
multiplier
=
3
;
for
idx
in
(
0
...
(
fixedCouponCode
.
count
-
1
))
.
reversed
()
{
let
curChar
=
fixedCouponCode
[
idx
];
result
+=
(
Int
(
curChar
)
??
0
)
*
multiplier
;
multiplier
=
multiplier
==
3
?
1
:
3
;
}
checkDigit
=
10
-
(
result
%
10
);
let
barcodeStr
=
fixedCouponCode
+
String
(
checkDigit
);
return
barcodeStr
;
}
return
""
}
var
body
:
some
View
{
let
barcodeString
=
constructBarcode
()
??
""
GeometryReader
{
geometry
in
ScrollView
(
showsIndicators
:
false
)
{
VStack
(
alignment
:
.
leading
)
{
...
...
@@ -131,7 +194,7 @@ extension CouponBarcodeView {
VStack
(
alignment
:
.
center
)
{
VStack
{
Text
(
"1A2C378
"
)
Text
(
coupon
[
"coupon"
]
as?
String
??
"
"
)
.
fontWeight
(
.
bold
)
.
font
(
.
system
(
size
:
27
))
.
foregroundColor
(
Color
(
red
:
0.2549019607843137
,
green
:
0.3333333333333333
,
blue
:
0.39215686274509803
))
...
...
@@ -166,7 +229,7 @@ extension CouponBarcodeView {
// gen.fillColor = UIColor.white
// gen.strokeColor = UIColor.black
if
let
barcodeImage
=
RSUnifiedCodeGenerator
.
shared
.
generateCode
(
"1234567891234"
,
machineReadableCodeObjectType
:
AVMetadataObject
.
ObjectType
.
ean13
.
rawValue
,
targetSize
:
CGSize
(
width
:
300
,
height
:
300
))
{
if
let
barcodeImage
=
RSUnifiedCodeGenerator
.
shared
.
generateCode
(
barcodeString
,
machineReadableCodeObjectType
:
AVMetadataObject
.
ObjectType
.
ean13
.
rawValue
,
targetSize
:
CGSize
(
width
:
300
,
height
:
300
))
{
// VStack(alignment: .center) {
// Image(uiImage: image)
...
...
@@ -200,7 +263,7 @@ extension CouponBarcodeView {
// .aspectRatio(contentMode: .fit)
// .frame(width: self.uiscreen.width, height: self.uiscreen.height * 0.1)
Text
(
"1234567891234"
)
Text
(
barcodeString
)
.
fontWeight
(
.
regular
)
.
font
(
.
system
(
size
:
22
))
.
foregroundColor
(
Color
(
red
:
0.2549019607843137
,
green
:
0.3333333333333333
,
blue
:
0.39215686274509803
))
...
...
Please
register
or
login
to post a comment