#import "ViewController.h"
#import "QRCodeGenerator.h"
@interface ViewController ()
{
//創(chuàng)建文本對象
? ? UITextField*textTf;
//創(chuàng)建圖片對象
? ? UIImageView*imagerView;
?}
@end
@implementation ViewController
- (void)viewDidLoad {
? ? [super viewDidLoad];
? ? UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
? ? btn.frame=CGRectMake(120,200,160,40);
? ? btn.backgroundColor = [UIColor redColor];
? ? [btnsetTitle:@"二維碼生成" forState:UIControlStateNormal];
? ? [btnaddTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
? ? [self.viewaddSubview:btn];
? ? textTf = [[UITextField alloc]initWithFrame:CGRectMake(100, 90, 160, 44)];
? ? textTf.backgroundColor = [UIColor yellowColor];
? ? [self.view addSubview:textTf];
? ? imagerView = [[UIImageView? alloc]initWithFrame:CGRectMake(20, 300, 300, 200)];
? ? imagerView.backgroundColor = [UIColor lightGrayColor];
? ? [self.view addSubview:imagerView];
}
//實現(xiàn)二維碼關(guān)鍵響應方法
-(void)click{
?? //關(guān)鍵是這一行代碼(生成二維碼)
? UIImage*image = [QRCodeGeneratorqrImageForString:textTf.text? ? imageSize:imagerView.bounds.size.width];
? imagerView.image= image;
}