Generate two-dimensional code:
1. After downloading Libqrencode three parties, pull into the project
2. In the header file reference #import "QRCodeGenerator.h"
3.:
4.
Code:
text box Uitextfield *textfield = [[Uitextfield alloc] Initwithframe:cgrectmake (20,20,200,50)]; [Self. View Addsubview:textfield]; TextField. backgroundcolor = [Uicolor Graycolor]; TextField. placeholder = @ "Please enter text"; Textfield.tag = 1; //button uibutton *button = [UIButton Buttonwithtype:uibuttontypesystem]; Button.frame = CGRectMake (250, 20 , 50, 50); [self.view Addsubview:button]; button .backgroundcolor = [uicolor Orangecolor]; [Button Settitle:@ "generate" forstate:uicontrolstatenormal]; [Button Addtarget:self action: @selector (QRCode) Forcontrolevents:uicontroleventtouchupinside];
Method:
- (void) QRCode {Uitextfield *textfield = [self. View Viewwithtag:1]; UIImage *image = [Qrcodegenerator qrimageforstring:textfield. Text imageSize:200]; Uiimageview *imageview = [[Uiimageview alloc] Initwithframe:cgrectmake ( 200)]; ImageView. Center = Self. View. Center; ImageView. image = Image; [self. View Addsubview:imageview];}
Warning
If you get a C99 error in the compilation, you can reference it in the #import "QRCodeGenerator.h" file:
Import
On the simple use of QR code