123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- #import "QRCodeEncoderDemoViewController.h"
- @implementation QRCodeEncoderDemoViewController
- - (void)dealloc
- {
- [super dealloc];
- }
- #pragma mark - View lifecycle
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
-
- //the qrcode is square. now we make it 250 pixels wide
- int qrcodeImageDimension = 250;
-
- //the string can be very long
- NSString* aVeryLongURL = @"http://thelongestlistofthelongeststuffatthelongestdomainnameatlonglast.com/";
-
- //first encode the string into a matrix of bools, TRUE for black dot and FALSE for white. Let the encoder decide the error correction level and version
- DataMatrix* qrMatrix = [QREncoder encodeWithECLevel:QR_ECLEVEL_AUTO version:QR_VERSION_AUTO string:aVeryLongURL];
-
- //then render the matrix
- UIImage* qrcodeImage = [QREncoder renderDataMatrix:qrMatrix imageDimension:qrcodeImageDimension];
-
- //put the image into the view
- UIImageView* qrcodeImageView = [[UIImageView alloc] initWithImage:qrcodeImage];
- CGRect parentFrame = self.view.frame;
- CGRect tabBarFrame = self.tabBarController.tabBar.frame;
-
- //center the image
- CGFloat x = (parentFrame.size.width - qrcodeImageDimension) / 2.0;
- CGFloat y = (parentFrame.size.height - qrcodeImageDimension - tabBarFrame.size.height) / 2.0;
- CGRect qrcodeImageViewFrame = CGRectMake(x, y, qrcodeImageDimension, qrcodeImageDimension);
- [qrcodeImageView setFrame:qrcodeImageViewFrame];
-
- //and that's it!
- [self.view addSubview:qrcodeImageView];
- [qrcodeImageView release];
- }
- @end
|