-
Notifications
You must be signed in to change notification settings - Fork 0
/
CardViewController.m
110 lines (90 loc) · 4.11 KB
/
CardViewController.m
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
109
110
//
// CardViewController.m
// MyLoyaltyCard_FC
//
// Created by Fede Cana on 07/05/2021.
// Copyright © 2021 Fede Cana. All rights reserved.
//
#import "CardViewController.h"
#import "CardDetailTableViewController.h"
@interface CardViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageViewOfCard;
@property (weak, nonatomic) IBOutlet UIImageView *imageViewOfLogo;
- (CIImage*)generateBarcode;
- (CIImage *)generateQrcode;
@property (weak, nonatomic) IBOutlet UILabel *colorCardLabel;
@property (weak, nonatomic) IBOutlet UILabel *codiceClienteLabel;
@property(nonatomic, strong) UIColor *backgroundColor;
- (void)getCardColor;
@end
@implementation CardViewController
- (void)viewDidLoad {
@try{
[super viewDidLoad];
//imposto il titolo della View
self.title = self.showCard.nomeAzienda;
//genero e setto il barcode oppure il qrcode
if([self.showCard.formatoCodice isEqualToString:@"Barcode"]){
CIImage *barcode = [self generateBarcode];
UIImage *barcodeImage = [[UIImage alloc] initWithCIImage:barcode];
self.imageViewOfCard.image = barcodeImage;
} else if([self.showCard.formatoCodice isEqualToString: @"QRcode"]){
CIImage *qrcode = [self generateQrcode];
UIImage *qrcodeImage = [[UIImage alloc] initWithCIImage:qrcode];
self.imageViewOfCard.image = qrcodeImage;
} else {
NSLog(@"Errore nessun formato del codice corrisponde!");
}
//genero e assegno il colore della carta
[self getCardColor];
self.colorCardLabel.backgroundColor = self.backgroundColor;
//imposto il codice cliente nella label che lo visualizza
self.codiceClienteLabel.text = self.showCard.codiceCliente;
//imposto il logo della carta
UIImage *imageLogo = [UIImage imageWithContentsOfFile:self.showCard.logo];
self.imageViewOfLogo.image = imageLogo;
} @catch(NSException *ex){
NSLog(@"Errore in CardViewController => %@",ex.reason);
}
}
-(CIImage*)generateBarcode{
CIFilter *barCodeFilter = [CIFilter filterWithName:@"CICode128BarcodeGenerator"];
NSData *barCodeData = [self.showCard.codiceCliente dataUsingEncoding:NSASCIIStringEncoding];
[barCodeFilter setValue:barCodeData forKey:@"inputMessage"];
[barCodeFilter setValue:[NSNumber numberWithFloat:0] forKey:@"inputQuietSpace"];
CIImage *barCodeImage = barCodeFilter.outputImage;
return barCodeImage;
}
- (CIImage *)generateQrcode{
NSData *stringData = [self.showCard.codiceCliente dataUsingEncoding: NSISOLatin1StringEncoding];
CIFilter *qrFilter = [CIFilter filterWithName:@"CIQRCodeGenerator"];
[qrFilter setValue:stringData forKey:@"inputMessage"];
return qrFilter.outputImage;
}
-(void) getCardColor{
if([self.showCard.coloreSfondo isEqual:@"Red"]){
self.backgroundColor = [[UIColor alloc] initWithRed:1 green:0 blue:0 alpha:1];
} else if([self.showCard.coloreSfondo isEqual:@"Green"]){
self.backgroundColor = [[UIColor alloc] initWithRed:0 green:1 blue:0 alpha:1];
} else if([self.showCard.coloreSfondo isEqual:@"Blue"]){
self.backgroundColor = [[UIColor alloc] initWithRed:0 green:0 blue:1 alpha:1];
} else if([self.showCard.coloreSfondo isEqual:@"Yellow"]){
self.backgroundColor = [[UIColor alloc] initWithRed:1 green:1 blue:0 alpha:1];
} else {
NSLog(@"Errore colore non corrispondente con quelli assegnati!");
}
}
- (IBAction)infoButtonTapped:(id)sender {
[self performSegueWithIdentifier: @"showCardDetail" sender: self];
}
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([segue.identifier isEqualToString:@"showCardDetail"]){
if([segue.destinationViewController isKindOfClass:[CardDetailTableViewController class]]){
CardDetailTableViewController *vc = (CardDetailTableViewController *)segue.destinationViewController;
vc.theCard = self.showCard;
}
}
}
@end