Showing
1 changed file
with
150 additions
and
64 deletions
| ... | @@ -10,7 +10,8 @@ import SwiftUI | ... | @@ -10,7 +10,8 @@ import SwiftUI |
| 10 | import Combine | 10 | import Combine |
| 11 | import Foundation | 11 | import Foundation |
| 12 | import UIKit | 12 | import UIKit |
| 13 | - | 13 | +//import RSBarcodes_Swift |
| 14 | +//import AVFoundation | ||
| 14 | 15 | ||
| 15 | 16 | ||
| 16 | extension CouponBarcodeView { | 17 | extension CouponBarcodeView { |
| ... | @@ -65,56 +66,136 @@ extension CouponBarcodeView { | ... | @@ -65,56 +66,136 @@ extension CouponBarcodeView { |
| 65 | } | 66 | } |
| 66 | } | 67 | } |
| 67 | 68 | ||
| 69 | + | ||
| 70 | + func generateBarcode(from string: String) -> Image? { | ||
| 71 | + | ||
| 72 | + let data = string.data(using: String.Encoding.ascii) | ||
| 73 | + | ||
| 74 | + if let filter = CIFilter(name: "CICode128BarcodeGenerator") { | ||
| 75 | + filter.setValue(data, forKey: "inputMessage") | ||
| 76 | +// let transform = CGAffineTransform(scaleX: 3, y: 3) | ||
| 77 | + | ||
| 78 | + | ||
| 79 | +// if let output = filter.outputImage?.transformed(by: transform) { | ||
| 80 | + if let output = filter.outputImage { | ||
| 81 | + | ||
| 82 | +// // Change the color using CIFilter | ||
| 83 | +// let colorParameters = [ | ||
| 84 | +// "inputColor0": CIColor(color: UIColor.black), // Foreground | ||
| 85 | +// "inputColor1": CIColor(color: UIColor.clear) // Background | ||
| 86 | +// ] | ||
| 87 | +// let colored = output.applyingFilter("CIFalseColor", parameters: colorParameters) | ||
| 88 | + let image = Image(uiImage: UIImage(ciImage: output)) | ||
| 89 | + | ||
| 90 | +// return UIImage(ciImage: output) | ||
| 91 | + return image | ||
| 92 | + } | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + return nil | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + | ||
| 68 | var body: some View { | 99 | var body: some View { |
| 69 | GeometryReader { geometry in | 100 | GeometryReader { geometry in |
| 70 | ScrollView(showsIndicators: false) { | 101 | ScrollView(showsIndicators: false) { |
| 71 | VStack(alignment: .leading) { | 102 | VStack(alignment: .leading) { |
| 72 | 103 | ||
| 73 | ImageView(withURL: coupon["img_preview"] as? String ?? "") | 104 | ImageView(withURL: coupon["img_preview"] as? String ?? "") |
| 74 | - | ||
| 75 | - Text(coupon["name"] as? String ?? "") | ||
| 76 | - .fontWeight(.bold) | ||
| 77 | - .font(.system(size: 16)) | ||
| 78 | - .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803)) | ||
| 79 | - .multilineTextAlignment(.leading) | ||
| 80 | - .padding(.horizontal) | ||
| 81 | - .padding(.top, self.uiscreen.height * 0.04) | ||
| 82 | - | ||
| 83 | - Text(coupon["short_description"] as? String ?? "") | ||
| 84 | - .fontWeight(.regular) | ||
| 85 | - .font(.system(size: 14)) | ||
| 86 | - .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803)) | ||
| 87 | - .multilineTextAlignment(.leading) | ||
| 88 | - .padding(.horizontal) | ||
| 89 | - .padding(.top, self.uiscreen.height * 0.02) | ||
| 90 | - | ||
| 91 | - VStack(alignment: .center) { | ||
| 92 | - VStack {} | ||
| 93 | - .frame(height: 1) | ||
| 94 | - .frame(width: self.uiscreen.width * 0.9) | ||
| 95 | - .background(Color(red: 0.9019607843137255, green: 0.9019607843137255, blue: 0.9019607843137255)) | ||
| 96 | - } | ||
| 97 | - .frame(maxWidth: .infinity) | ||
| 98 | - | ||
| 99 | 105 | ||
| 100 | - | 106 | + VStack(alignment: .leading) { |
| 101 | - VStack(alignment: .center) { | 107 | + Text(coupon["name"] as? String ?? "") |
| 102 | - VStack {} | 108 | + .fontWeight(.bold) |
| 103 | - .frame(height: 1) | 109 | + .font(.system(size: 16)) |
| 104 | - .frame(width: self.uiscreen.width * 0.9) | 110 | + .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803)) |
| 105 | - .background(Color(red: 0.9019607843137255, green: 0.9019607843137255, blue: 0.9019607843137255)) | 111 | + .multilineTextAlignment(.leading) |
| 112 | + .padding(.horizontal) | ||
| 113 | + .padding(.top, self.uiscreen.height * 0.04) | ||
| 114 | + | ||
| 115 | + Text(coupon["short_description"] as? String ?? "") | ||
| 116 | + .fontWeight(.regular) | ||
| 117 | + .font(.system(size: 14)) | ||
| 118 | + .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803)) | ||
| 119 | + .multilineTextAlignment(.leading) | ||
| 120 | + .padding(.horizontal) | ||
| 121 | + .padding(.top, self.uiscreen.height * 0.02) | ||
| 122 | + | ||
| 123 | + Text("Κωδικός Κουπονιού") | ||
| 124 | + .fontWeight(.medium) | ||
| 125 | + .font(.system(size: 16)) | ||
| 126 | + .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803)) | ||
| 127 | + .multilineTextAlignment(.center) | ||
| 128 | + .padding(.top, self.uiscreen.height * 0.05) | ||
| 129 | + .padding(.horizontal) | ||
| 130 | + .frame(maxWidth: .infinity) | ||
| 131 | + | ||
| 132 | + VStack(alignment: .center) { | ||
| 133 | + VStack { | ||
| 134 | + Text("1A2C378") | ||
| 135 | + .fontWeight(.bold) | ||
| 136 | + .font(.system(size: 27)) | ||
| 137 | + .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803)) | ||
| 138 | + .multilineTextAlignment(.center) | ||
| 139 | + .padding(.horizontal) | ||
| 140 | + .padding(.vertical, 10) | ||
| 141 | +// .padding(.all) | ||
| 142 | + } | ||
| 143 | + .frame(width: self.uiscreen.width * 0.8) | ||
| 144 | + .background(Color(red: 0.9333333333333333, green: 0.9686274509803922, blue: 1.0)) | ||
| 145 | + .cornerRadius(10) | ||
| 146 | + } | ||
| 147 | + .frame(maxWidth: .infinity) | ||
| 148 | + | ||
| 149 | + if (CharacterSet.decimalDigits.isSuperset(of: CharacterSet(charactersIn: "123456789101112"))) { | ||
| 150 | + VStack(alignment: .center) { | ||
| 151 | + VStack {} | ||
| 152 | + .frame(height: 1) | ||
| 153 | + .frame(width: self.uiscreen.width * 0.9) | ||
| 154 | + .background(Color(red: 0.9019607843137255, green: 0.9019607843137255, blue: 0.9019607843137255)) | ||
| 155 | + } | ||
| 156 | + .frame(maxWidth: .infinity) | ||
| 157 | + .padding(.top, self.uiscreen.height * 0.015) | ||
| 158 | + | ||
| 159 | + // TODO: Add the barcode | ||
| 160 | +// generateBarcode(from: "1234567891234") | ||
| 161 | +// ? | ||
| 162 | +// .resizable() | ||
| 163 | +// .aspectRatio(contentMode: .fit) | ||
| 164 | +// .frame(width: self.uiscreen.width, height: self.uiscreen.height * 0.1) | ||
| 165 | + | ||
| 166 | + Text("123456789101112") | ||
| 167 | + .fontWeight(.regular) | ||
| 168 | + .font(.system(size: 22)) | ||
| 169 | + .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803)) | ||
| 170 | + .multilineTextAlignment(.center) | ||
| 171 | + .padding(.vertical, self.uiscreen.height * 0.01) | ||
| 172 | + .padding(.horizontal) | ||
| 173 | + .frame(maxWidth: .infinity) | ||
| 174 | + | ||
| 175 | + | ||
| 176 | + VStack(alignment: .center) { | ||
| 177 | + VStack {} | ||
| 178 | + .frame(height: 1) | ||
| 179 | + .frame(width: self.uiscreen.width * 0.9) | ||
| 180 | + .background(Color(red: 0.9019607843137255, green: 0.9019607843137255, blue: 0.9019607843137255)) | ||
| 181 | + } | ||
| 182 | + .frame(maxWidth: .infinity) | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + | ||
| 186 | + | ||
| 187 | + Text("Το κουπόνι ισχύει έως " + CouponBarcodeView.couponContainer.convertDateFormat(inputDate: coupon["expiration"] as? String ?? "")) | ||
| 188 | + .fontWeight(.medium) | ||
| 189 | + .font(.system(size: 14)) | ||
| 190 | + .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803)) | ||
| 191 | + .multilineTextAlignment(.center) | ||
| 192 | + .padding(.top, self.uiscreen.height * 0.03) | ||
| 193 | + .padding(.horizontal) | ||
| 194 | + .frame(maxWidth: .infinity) | ||
| 106 | } | 195 | } |
| 107 | - .frame(maxWidth: .infinity) | 196 | + .frame(width:self.uiscreen.width) |
| 108 | - | 197 | + |
| 109 | 198 | ||
| 110 | - Text("Το κουπόνι ισχύει έως " + CouponBarcodeView.couponContainer.convertDateFormat(inputDate: coupon["img_preview"] as? String ?? "")) | ||
| 111 | - .fontWeight(.medium) | ||
| 112 | - .font(.system(size: 14)) | ||
| 113 | - .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803)) | ||
| 114 | - .multilineTextAlignment(.center) | ||
| 115 | - .padding(.top, self.uiscreen.height * 0.03) | ||
| 116 | - .padding(.horizontal) | ||
| 117 | - .frame(maxWidth: .infinity) | ||
| 118 | 199 | ||
| 119 | Spacer() | 200 | Spacer() |
| 120 | 201 | ||
| ... | @@ -130,35 +211,39 @@ extension CouponBarcodeView { | ... | @@ -130,35 +211,39 @@ extension CouponBarcodeView { |
| 130 | .foregroundColor(Color(red: 0.3137254901960784, green: 0.6196078431372549, blue: 0.1843137254901961)) | 211 | .foregroundColor(Color(red: 0.3137254901960784, green: 0.6196078431372549, blue: 0.1843137254901961)) |
| 131 | .multilineTextAlignment(.center) | 212 | .multilineTextAlignment(.center) |
| 132 | .padding(.all) | 213 | .padding(.all) |
| 214 | + | ||
| 215 | + // TODO: Add gift icon | ||
| 133 | } | 216 | } |
| 217 | + .frame(maxWidth: .infinity) | ||
| 134 | } | 218 | } |
| 135 | .frame(width: self.uiscreen.width * 0.8) | 219 | .frame(width: self.uiscreen.width * 0.8) |
| 136 | .background(Color(red: 0.9019607843137255, green: 0.9019607843137255, blue: 0.9019607843137255)) | 220 | .background(Color(red: 0.9019607843137255, green: 0.9019607843137255, blue: 0.9019607843137255)) |
| 137 | .cornerRadius(7) | 221 | .cornerRadius(7) |
| 138 | } | 222 | } |
| 139 | .frame(maxWidth: .infinity) | 223 | .frame(maxWidth: .infinity) |
| 140 | - .padding(.top, self.uiscreen.height * 0.1) | 224 | + .padding(.top, self.uiscreen.height * 0.05) |
| 141 | 225 | ||
| 142 | - VStack(alignment: .center) { | 226 | +// VStack(alignment: .center) { |
| 143 | - Button { | 227 | +// Button { |
| 144 | - // Button Action | 228 | +// // Button Action |
| 145 | - print("Shops Map Button tapped!") | 229 | +// print("Shops Map Button tapped!") |
| 146 | - } label: { | 230 | +// } label: { |
| 147 | - HStack { | 231 | +// HStack { |
| 148 | - Text("Χάρτης Καταστημάτων") | 232 | +// Text("Χάρτης Καταστημάτων") |
| 149 | - .fontWeight(.medium) | 233 | +// .fontWeight(.medium) |
| 150 | - .font(.system(size: 16)) | 234 | +// .font(.system(size: 16)) |
| 151 | - .foregroundColor(Color.white) | 235 | +// .foregroundColor(Color.white) |
| 152 | - .multilineTextAlignment(.center) | 236 | +// .multilineTextAlignment(.center) |
| 153 | - .padding(.all) | 237 | +// .padding(.all) |
| 154 | - } | 238 | +// } |
| 155 | - } | 239 | +// .frame(maxWidth: .infinity) |
| 156 | - .frame(width: self.uiscreen.width * 0.8) | 240 | +// } |
| 157 | - .background(Color(red: 0.4745098039215686, green: 0.7490196078431373, blue: 0.0784313725490196)) | 241 | +// .frame(width: self.uiscreen.width * 0.8) |
| 158 | - .cornerRadius(7) | 242 | +// .background(Color(red: 0.4745098039215686, green: 0.7490196078431373, blue: 0.0784313725490196)) |
| 159 | - } | 243 | +// .cornerRadius(7) |
| 160 | - .frame(maxWidth: .infinity) | 244 | +// } |
| 161 | - .padding(.top, self.uiscreen.height * 0.02) | 245 | +// .frame(maxWidth: .infinity) |
| 246 | +// .padding(.top, self.uiscreen.height * 0.015) | ||
| 162 | 247 | ||
| 163 | Button { | 248 | Button { |
| 164 | // Button Action | 249 | // Button Action |
| ... | @@ -170,7 +255,8 @@ extension CouponBarcodeView { | ... | @@ -170,7 +255,8 @@ extension CouponBarcodeView { |
| 170 | .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803)) | 255 | .foregroundColor(Color(red: 0.2549019607843137, green: 0.3333333333333333, blue: 0.39215686274509803)) |
| 171 | .underline() | 256 | .underline() |
| 172 | .multilineTextAlignment(.center) | 257 | .multilineTextAlignment(.center) |
| 173 | - .padding(.vertical, self.uiscreen.height * 0.03) | 258 | + .padding(.top, self.uiscreen.height * 0.025) |
| 259 | + .padding(.bottom, self.uiscreen.height * 0.03) | ||
| 174 | .padding(.horizontal) | 260 | .padding(.horizontal) |
| 175 | .frame(maxWidth: .infinity) | 261 | .frame(maxWidth: .infinity) |
| 176 | } | 262 | } | ... | ... |
-
Please register or login to post a comment